我现在有一个rewrite配置如下
<IfModule rewrite_module>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php/$1 [QSA,PT,L]
</IfModule>
写在主配置文件可以用
但是放到.htaccess中 却要写成RewriteRule ^(.*)$ /index.php?$1 [QSA,PT,L]
求答疑
分别访问localhost/a
这是配置放在.htaccess文件中的tracelog
返回404
[Fri Oct 21 15:00:55.952317 2016] [rewrite:trace2] [pid 7652:tid 1796] mod_rewrite.c(476): [client ::1:51051] ::1 - - [localhost/sid#45a368][rid#4b6b48/initial] [perdir D:/phpStudy/WWW/] rewrite 'a' -> '/index.php/a'
[Fri Oct 21 15:00:55.952317 2016] [rewrite:trace2] [pid 7652:tid 1796] mod_rewrite.c(476): [client ::1:51051] ::1 - - [localhost/sid#45a368][rid#4b6b48/initial] [perdir D:/phpStudy/WWW/] forcing '/index.php/a' to get passed through to next API URI-to-filename handler
[Fri Oct 21 15:00:55.952317 2016] [rewrite:trace2] [pid 7652:tid 1796] mod_rewrite.c(476): [client ::1:51051] ::1 - - [localhost/sid#45a368][rid#4b6b48/initial] [perdir D:/phpStudy/WWW/] trying to replace context docroot D:/phpStudy/WWW with context prefix
[Fri Oct 21 15:00:55.952317 2016] [rewrite:trace1] [pid 7652:tid 1796] mod_rewrite.c(476): [client ::1:51051] ::1 - - [localhost/sid#45a368][rid#4b6b48/initial] [perdir D:/phpStudy/WWW/] internal redirect with /index.php/a [INTERNAL REDIRECT]
[Fri Oct 21 15:00:55.952317 2016] [rewrite:trace1] [pid 7652:tid 1796] mod_rewrite.c(476): [client ::1:51051] ::1 - - [localhost/sid#45a368][rid#4b8028/initial/redir#1] [perdir D:/phpStudy/WWW/] pass through D:/phpStudy/WWW/index.php
[Fri Oct 21 15:00:55.952317 2016] [rewrite:trace2] [pid 7652:tid 1796] mod_rewrite.c(476): [client ::1:51051] ::1 - - [localhost/sid#45a368][rid#4c6b88/subreq] [perdir D:/phpStudy/WWW/] rewrite 'a' -> '/index.php/a'
[Fri Oct 21 15:00:55.953317 2016] [rewrite:trace2] [pid 7652:tid 1796] mod_rewrite.c(476): [client ::1:51051] ::1 - - [localhost/sid#45a368][rid#4c6b88/subreq] [perdir D:/phpStudy/WWW/] forcing '/index.php/a' to get passed through to next API URI-to-filename handler
[Fri Oct 21 15:00:55.953317 2016] [rewrite:trace2] [pid 7652:tid 1796] mod_rewrite.c(476): [client ::1:51051] ::1 - - [localhost/sid#45a368][rid#4c6b88/subreq] [perdir D:/phpStudy/WWW/] trying to replace context docroot D:/phpStudy/WWW with context prefix
[Fri Oct 21 15:00:55.953317 2016] [rewrite:trace1] [pid 7652:tid 1796] mod_rewrite.c(476): [client ::1:51051] ::1 - - [localhost/sid#45a368][rid#4c6b88/subreq] [perdir D:/phpStudy/WWW/] internal redirect with /index.php/a [INTERNAL REDIRECT]
这是配置放在httpd.conf中的tracelog
成功访问index.php
[Fri Oct 21 15:06:35.486352 2016] [rewrite:trace2] [pid 5452:tid 1796] mod_rewrite.c(476): [client ::1:51105] ::1 - - [localhost/sid#1f5a368][rid#1fbeb68/initial] init rewrite engine with requested uri /a
[Fri Oct 21 15:06:35.486352 2016] [rewrite:trace2] [pid 5452:tid 1796] mod_rewrite.c(476): [client ::1:51105] ::1 - - [localhost/sid#1f5a368][rid#1fbeb68/initial] rewrite '/a' -> '/index.php//a'
[Fri Oct 21 15:06:35.486352 2016] [rewrite:trace2] [pid 5452:tid 1796] mod_rewrite.c(476): [client ::1:51105] ::1 - - [localhost/sid#1f5a368][rid#1fbeb68/initial] forcing '/index.php//a' to get passed through to next API URI-to-filename handler
[Fri Oct 21 15:06:35.487352 2016] [rewrite:trace2] [pid 5452:tid 1796] mod_rewrite.c(476): [client ::1:51105] ::1 - - [localhost/sid#1f5a368][rid#1fc4b80/subreq] init rewrite engine with requested uri /a
[Fri Oct 21 15:06:35.487352 2016] [rewrite:trace2] [pid 5452:tid 1796] mod_rewrite.c(476): [client ::1:51105] ::1 - - [localhost/sid#1f5a368][rid#1fc4b80/subreq] rewrite '/a' -> '/index.php//a'
[Fri Oct 21 15:06:35.487352 2016] [rewrite:trace2] [pid 5452:tid 1796] mod_rewrite.c(476): [client ::1:51105] ::1 - - [localhost/sid#1f5a368][rid#1fc4b80/subreq] forcing '/index.php//a' to get passed through to next API URI-to-filename handler