我完全被mod_rewrite的伏都教所知。我们最近在aws上重新定位到一个新的ubuntu服务器,除了一个.htaccess文件之外,所有服务器似乎都正常工作。这个文件在之前的服务器上运行良好,但它在新服务器上运行良好。
有关页面是testing.sonicdad.com/members/admin/。这应该重定向到testing.sonicdad.com/members/admin.php而不是testing.sonicdad.com/members/admin/index.php
我已将.htaccess删除为此页面的相关代码,但仍然存在问题。请参阅以下内容:
RewriteEngine On
RewriteBase /members
## Append Trailing "/" to URL if absent ##
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ /members/$1/ [L,R=301]
RewriteRule ^admin/$ admin.php [L]
这是日志的相关部分
[rewrite:trace3] [pid 26730] mod_rewrite.c(468): [client 121.202.24.118:13894] 121.202.24.118 - - [testing.sonicdad.com/sid#7f8e16990038][rid#7f8e168600a0/initial] [perdir /var/www/html/members/] strip per-dir prefix: /var/www/html/members/admin/ -> admin/
[rewrite:trace3] [pid 26730] mod_rewrite.c(468): [client 121.202.24.118:13894] 121.202.24.118 - - [testing.sonicdad.com/sid#7f8e16990038][rid#7f8e168600a0/initial] [perdir /var/www/html/members/] applying pattern '^(.*)$' to uri 'admin/'
[rewrite:trace4] [pid 26730] mod_rewrite.c(468): [client 121.202.24.118:13894] 121.202.24.118 - - [testing.sonicdad.com/sid#7f8e16990038][rid#7f8e168600a0/initial] [perdir /var/www/html/members/] RewriteCond: input='/var/www/html/members/admin/' pattern='!-f' => matched
[rewrite:trace4] [pid 26730] mod_rewrite.c(468): [client 121.202.24.118:13894] 121.202.24.118 - - [testing.sonicdad.com/sid#7f8e16990038][rid#7f8e168600a0/initial] [perdir /var/www/html/members/] RewriteCond: input='/members/admin/' pattern='!(.*)/$' => not-matched
[rewrite:trace3] [pid 26730] mod_rewrite.c(468): [client 121.202.24.118:13894] 121.202.24.118 - - [testing.sonicdad.com/sid#7f8e16990038][rid#7f8e168600a0/initial] [perdir /var/www/html/members/] strip per-dir prefix: /var/www/html/members/admin/ -> admin/
[rewrite:trace3] [pid 26730] mod_rewrite.c(468): [client 121.202.24.118:13894] 121.202.24.118 - - [testing.sonicdad.com/sid#7f8e16990038][rid#7f8e168600a0/initial] [perdir /var/www/html/members/] applying pattern '^admin/$' to uri 'admin/'
[rewrite:trace2] [pid 26730] mod_rewrite.c(468): [client 121.202.24.118:13894] 121.202.24.118 - - [testing.sonicdad.com/sid#7f8e16990038][rid#7f8e168600a0/initial] [perdir /var/www/html/members/] rewrite 'admin/' -> 'admin.php'
[rewrite:trace3] [pid 26730] mod_rewrite.c(468): [client 121.202.24.118:13894] 121.202.24.118 - - [testing.sonicdad.com/sid#7f8e16990038][rid#7f8e168600a0/initial] [perdir /var/www/html/members/] add per-dir prefix: admin.php -> /var/www/html/members/admin.php
[rewrite:trace2] [pid 26730] mod_rewrite.c(468): [client 121.202.24.118:13894] 121.202.24.118 - - [testing.sonicdad.com/sid#7f8e16990038][rid#7f8e168600a0/initial] [perdir /var/www/html/members/] trying to replace prefix /var/www/html/members/ with /members
[rewrite:trace4] [pid 26730] mod_rewrite.c(468): [client 121.202.24.118:13894] 121.202.24.118 - - [testing.sonicdad.com/sid#7f8e16990038][rid#7f8e168600a0/initial] add subst prefix: admin.php -> /members/admin.php
[rewrite:trace1] [pid 26730] mod_rewrite.c(468): [client 121.202.24.118:13894] 121.202.24.118 - - [testing.sonicdad.com/sid#7f8e16990038][rid#7f8e168600a0/initial] [perdir /var/www/html/members/] internal redirect with /members/admin.php [INTERNAL REDIRECT]
[rewrite:trace1] [pid 26730] mod_rewrite.c(468): [client 121.202.24.118:13894] 121.202.24.118 - - [testing.sonicdad.com/sid#7f8e16990038][rid#7f8e0ced10a0/subreq] [perdir /var/www/html/members/] pass through /var/www/html/members/admin/index.html
[rewrite:trace1] [pid 26730] mod_rewrite.c(468): [client 121.202.24.118:13894] 121.202.24.118 - - [testing.sonicdad.com/sid#7f8e16990038][rid#7f8e0ced10a0/subreq] [perdir /var/www/html/members/] pass through /var/www/html/members/admin/index.cgi
[rewrite:trace1] [pid 26730] mod_rewrite.c(468): [client 121.202.24.118:13894] 121.202.24.118 - - [testing.sonicdad.com/sid#7f8e16990038][rid#7f8e0ced10a0/subreq] [perdir /var/www/html/members/] pass through /var/www/html/members/admin/index.pl
[rewrite:trace1] [pid 26730] mod_rewrite.c(468): [client 121.202.24.118:13894] 121.202.24.118 - - [testing.sonicdad.com/sid#7f8e16990038][rid#7f8e0ced10a0/subreq] [perdir /var/www/html/members/] pass through /var/www/html/members/admin/index.php
问题似乎是内部重定向。我要停止这个我尝试将标志修改为[END]。我也尝试过以下各种变体:
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]
RewriteCond %{ENV:REDIRECT_STATUS} !=200
有人可以告诉我如何在应用规则后停止此内部重定向。
由于
答案 0 :(得分:0)
这里有其他.htaccess文件吗?就像你在/ admin /?
这样的任何子目录中一样同时尝试更换htaccess文件的最后两行,
RewriteRule ^admin/$ admin.php [L]
RewriteRule ^(.*)$ /members/$1/ [L,R=301]
据我所知,Switch [L]意味着它的最后一条规则。尝试删除它。
答案 1 :(得分:0)
我们无法解决此问题,因此我们修改了文件夹结构,因此没有副本文件名和文件夹名称,即admin.php和admin /.
这实际上意味着我们有一个更清晰,更具描述性的文件夹结构,我很满意