mod_rewrite 规则无效,但我的语法正确
mod_rewrite rule is not working but I have the correct syntax
所以我的 mod_rewrite 规则无法为 URL.
指定特定的 php 文件
Options -Indexes
php_value short_open_tag 1
#Caching
# 1 HOUR
<FilesMatch "\.(ico|pdf|flv)$">
Header set Cache-Control "max-age=31536000, public"
</FilesMatch>
# 1 HOUR
<FilesMatch "\.(jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=31536000, public"
</FilesMatch>
# 1 HOUR
<FilesMatch "\.(xml|txt|css|js)$">
Header set Cache-Control "max-age=31536000, proxy-revalidate"
</FilesMatch>
<IfModule mod_rewrite.c>
#Rewrite rules
RewriteEngine on
RewriteRule ^about\/special-offers\/?$ about/special-offers.php
# remove www. from all domains
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [L,R=301]
# Add trailing slash
# TODO: This breaks POST data when forwarding to a URL without an ending slash
#RewriteCond %{REQUEST_URI} !\.(php|html?|gif|jpe?g|JPE?G|png|bmp|js|swf|css|ico|xml|txt|woff2|woff)$
#RewriteRule ^(.*)([^/])$ http://%{HTTP_HOST}// [P,R=301]
# hide .svn folders
RewriteRule ^(.*/)*\.svn/ / [NC,L]
# send all images and misc files to the actual location
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteRule \.(gif|jpe?g|JPE?G|png|bmp|js|swf|ico|xml|txt) index.php [NC,L]
# send folder to the relevant php file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ .php
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteRule ^([^/]+)/([^/]+)/([^/]+)/$ /.php
RewriteRule ^([^/]+)\/([^/]+)\/ /.php
#RewriteRule ^([^/]+)/([^/]+)/$ /.php
RewriteRule ^([^/]+)/([^/]+)/$ /default.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ // [R=301,L]
# otherwise if the file or directory is not found, process through the index
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]
</IfModule>
我这里有很多其他规则,如果需要我可以 post 它们,但由于这是一个特定的规则,我不知道为什么其中一个会覆盖它。指导表示赞赏。
我试过将它放在 mod_rewrite 部分的顶部或底部,但似乎都没有任何影响。
我刚刚注意到的是,当我转到 /about/special-offers/x
(其中 x 是任何字符串)时,它会加载正确的页面。
其他
终于解决了这个问题,我通过使用 [L] 将 RewriteRule 标记为 final 来做到这一点。
相关部分:
# send folder to the relevant php file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ .php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)\/([^/]+)\/ /.php [L]
所以我的 mod_rewrite 规则无法为 URL.
指定特定的 php 文件Options -Indexes
php_value short_open_tag 1
#Caching
# 1 HOUR
<FilesMatch "\.(ico|pdf|flv)$">
Header set Cache-Control "max-age=31536000, public"
</FilesMatch>
# 1 HOUR
<FilesMatch "\.(jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=31536000, public"
</FilesMatch>
# 1 HOUR
<FilesMatch "\.(xml|txt|css|js)$">
Header set Cache-Control "max-age=31536000, proxy-revalidate"
</FilesMatch>
<IfModule mod_rewrite.c>
#Rewrite rules
RewriteEngine on
RewriteRule ^about\/special-offers\/?$ about/special-offers.php
# remove www. from all domains
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [L,R=301]
# Add trailing slash
# TODO: This breaks POST data when forwarding to a URL without an ending slash
#RewriteCond %{REQUEST_URI} !\.(php|html?|gif|jpe?g|JPE?G|png|bmp|js|swf|css|ico|xml|txt|woff2|woff)$
#RewriteRule ^(.*)([^/])$ http://%{HTTP_HOST}// [P,R=301]
# hide .svn folders
RewriteRule ^(.*/)*\.svn/ / [NC,L]
# send all images and misc files to the actual location
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteRule \.(gif|jpe?g|JPE?G|png|bmp|js|swf|ico|xml|txt) index.php [NC,L]
# send folder to the relevant php file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ .php
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteRule ^([^/]+)/([^/]+)/([^/]+)/$ /.php
RewriteRule ^([^/]+)\/([^/]+)\/ /.php
#RewriteRule ^([^/]+)/([^/]+)/$ /.php
RewriteRule ^([^/]+)/([^/]+)/$ /default.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ // [R=301,L]
# otherwise if the file or directory is not found, process through the index
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]
</IfModule>
我这里有很多其他规则,如果需要我可以 post 它们,但由于这是一个特定的规则,我不知道为什么其中一个会覆盖它。指导表示赞赏。
我试过将它放在 mod_rewrite 部分的顶部或底部,但似乎都没有任何影响。
我刚刚注意到的是,当我转到 /about/special-offers/x
(其中 x 是任何字符串)时,它会加载正确的页面。
其他
终于解决了这个问题,我通过使用 [L] 将 RewriteRule 标记为 final 来做到这一点。
相关部分:
# send folder to the relevant php file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ .php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)\/([^/]+)\/ /.php [L]