我从一个网站项目开始,我想用动态长度重写 url。例如,以下 url 可以存在于站点中:
http://www.url.com/signup/
或者
http://www.url.com/profile/mark/pm/compose/
现在我有一个 .htaccess 脚本工作,但我怀疑它的效率。这是代码:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?page=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?page=$1
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ index.php?page=$1&subone=$2
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ index.php?page=$1&subone=$2
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ index.php? page=$1&subone=$2&subtwo=$3
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ index.php?page=$1&subone=$2&subtwo=$3
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ index.php?page=$1&subone=$2&subtwo=$3&subthree=$4
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ index.php?page=$1&subone=$2&subtwo=$3&subthree=$4
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ index.php?arg[0]=$1&arg[1]=$2&arg[2]=$3&arg[3]=$4&arg[4]=$5
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ index.php?arg[0]=$1&arg[1]=$2&arg[2]=$3&arg[3]=$4&arg[4]=$5
我实际上想做这样的事情,但我不知道我是如何让它工作的......
RewriteRule ^{[a-zA-Z0-9_-]+}/$ index.php?urlvar={$#}
所以网址
http://www.url.com/profile/mark/pm/compose/
会导致
http://www.url.com/index.php?urlvar[0]=profile&urlvar[1]=mark&urlvar[2]=pm&urlvar[3]=compose
谁知道如何解决这个问题?