如何设置mod_rewrite?我的目录结构如下(www.example.com/user/account /)
index.php
.htaccess
的.htaccess
DirectorySlash Off
RewriteEngine on
RewriteBase /user/account/
RewriteRule ^([\w-]+)/?$ index.php?command=$1 [L,QSA]
RewriteCond %{DOCUMENT_ROOT}/$1 -d
RewriteRule ^(.*?[^/])$ %{REQUEST_URI}/ [L,R=302]
我可以访问www.example.com/user/account/setting
command =setting
但我无法访问www.example.com/user/account/setting/
command =setting
当我改变
RewriteRule ^([\w-]+)/?$ index.php?command=$1&page=$2 [L,QSA]
我无法访问www.example.com/user/account/setting/1
command =setting & page = 1
请帮助我如何访问以下链接?
www.example.com/user/account/setting/1
答案 0 :(得分:2)
您需要有一个新规则来处理page
参数,方法是从漂亮的URI中捕获它:
DirectorySlash Off
RewriteEngine on
RewriteBase /user/account/
RewriteRule ^([\w-]+)/?$ index.php?command=$1 [L,QSA]
RewriteRule ^([\w-]+)/(\d+)/?$ index.php?command=$1&page=$2 [L,QSA]
RewriteCond %{DOCUMENT_ROOT}/$1 -d
RewriteRule ^(.*?[^/])$ %{REQUEST_URI}/ [L,R=302]