htaccess没有做我想做的事

时间:2014-06-03 04:40:16

标签: php .htaccess

#### ADMINISTRATION PANEL ####
RewriteRule ^administration/main administration/index.php [L]                                       ## Administration - Main
RewriteRule ^administration/members/list administration/members.php?list=view [L]                   ## Administration - User List
RewriteRule ^administration/members/reports administration/members.php?reports=view [L]             ## Administration - User Reports
RewriteRule ^administration/members/banned administration/members.php?banned=view [L]               ## Administration - User Banned

RewriteRule ^administration/members/list/page([^/]*)$ administration/members.php?list=view&page=$1 [L]          ## Administration - User List - Pagination
RewriteRule ^administration/members/reports/page([^/]*)$ administration/members.php?reports=view&page=$1 [L]    ## Administration - User Reports  - Pagination
RewriteRule ^administration/members/banned/page([^/]*)$ administration/members.php?banned=view&page=$1 [L]      ## Administration - User Banned  - Pagination

如果我使用直接链接“administration / members.php?list = view& page34它可以工作.....但是没有,不是用htaccess重写,总bs。帮助我吗?

1 个答案:

答案 0 :(得分:0)

关于重写规则,你必须记住的是它们是正则表达式匹配器。你的问题是这种模式

^administration/members/list

将匹配此网址

http://example.com/administration/members/list/page34

在此规则之前

^administration/members/list/page([^/]*)$

我建议你在你的第一套模式上放一个EOL锚($),如果这是他们实际匹配的,例如

RewriteRule ^administration/main$ administration/index.php [L]
RewriteRule ^administration/members/list$ administration/members.php?list=view [L]
RewriteRule ^administration/members/reports$ administration/members.php?reports=view [L]
RewriteRule ^administration/members/banned$ administration/members.php?banned=view [L] 

我还建议您使用QSA标志,以免丢失任何额外的查询字符串信息。

更新

更好的想法是将您的第一组规则与其分页等效项合并。例如

RewriteRule ^administration/members/list(/page(\d+))? administration/members.php?list=view&page=$2 [L,QSA]

这最终会像这样......

administration/members/list        => administration/members.php?list=view&page=
administration/members/list/page34 => administration/members.php?list=view&page=34