以下是我在.htaccess
文件中使用url重写的代码
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule pages/(.*)/? /page/index.php?name=$1 [NC,L]
如果网址为www.example.com/pages/2
,则从上面的代码然后实际上转到网址www.example.com/page/index.php?name=2
但我也希望这样:如果页面请求是www.example.com/pages/2/user/rahul
,那么它也应该转到相同的网址www.example.com/page/index.php?name=2&user=rahul
所以做上面的事情我做了这样的事情:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule pages/(.*)/? /page/index.php?name=$1 [NC,L]
RewriteRule pages/(.*)/user/(.*)/? /page/index.php?name=$1&user=$2 [NC,L]
但它确实按我的意愿工作。
答案 0 :(得分:0)
尝试:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule ^pages/([^/]+)/user/([^/]+)/?$ /page/index.php?name=$1&user=$2 [NC,L]
RewriteRule ^pages/([^/]+)/?$ /page/index.php?name=$1 [NC,L]