【发布时间】:2015-10-27 07:05:17
【问题描述】:
我希望将http://example.com/admin/pages/index.php 重写为http://example.com/index.php?admin=admin&cid=pages。
它适用于http://example.com/admin/pages(我也想要),但不适用于http://example.com/admin/pages/index.php。
这是如何实现的?
重写引擎开启 重写基础/
# If the request is for a valid directory, file, or link, don't do anything
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^ - [L]
#remove the trailing slash
RewriteRule (.+)/$ $1
# If you add this first rule to support views, be sure to remove the QSA flag from the second rule (maybe not required since the first rule has the L flag)
#replace admin/cid with index.php?admin=admin&cid=cid
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?admin=$1&cid=$2 [L,QSA]
#replace mypage with index.php?admin=mypage
RewriteRule ^([^/]+)/?$ index.php?admin=$1 [L,QSA]
编辑
随机变化表明这可能是正确的。
RewriteRule ^([^/]+)/([^/]+)/index.php/?$ index.php?admin=$1&cid=$2 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?admin=$1&cid=$2 [L,QSA]
#replace mypage with index.php?admin=mypage
RewriteRule ^([^/]+)/index.php/?$ index.php?admin=$1 [L,QSA]
RewriteRule ^([^/]+)/?$ index.php?admin=$1 [L,QSA]
【问题讨论】:
标签: regex apache .htaccess mod-rewrite