如何允许.php,尾随斜杠,没有斜杠?

时间:2011-04-06 02:28:43

标签: .htaccess url mod-rewrite clean-urls

如何允许.php,尾随斜杠和没有尾随斜杠?

RewriteEngine on

RewriteCond %{REQUEST_URI} (.*)(\.php|\/)$
RewriteRule (.*)$ %1 [R=301,L]

DirectoryIndex index.php
#directory ban
Options All -Indexes

ErrorDocument 400 /error.php
ErrorDocument 404 /error.php
ErrorDocument 500 /error.php

FileETag MTime Size
ExpiresActive on
ExpiresDefault "access plus 86400 seconds"

# 1 WEEK
<FilesMatch "\.(jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
# 2 DAYS
<FilesMatch "\.(xml|txt|css|js)$">
Header set Cache-Control "max-age=172800, proxy-revalidate"
</FilesMatch>
# 1 MIN
<FilesMatch "\.(html|htm|php)$">
Header set Cache-Control "max-age=60, private, proxy-revalidate"
</FilesMatch>

<IfModule mod_expires.c>
# any Expires Directives go here
</IfModule>

<IfModule mod_headers.c>
# any Header directives go here
</IfModule>

<ifmodule mod_deflate.c="">
<filesmatch ".(js|css)$"="">
SetOutputFilter DEFLATE
</filesmatch>
</ifmodule>
RewriteCond %{HTTP_HOST} !^mydomain\.com$ [NC]
RewriteRule ^(.*)$ mydomain.com/$1 [R=301,L]

2 个答案:

答案 0 :(得分:1)

尝试使用此修改后的.htaccess文件:

RewriteEngine on
DirectoryIndex index.php
Options All -Indexes

ErrorDocument 400 /error.php
ErrorDocument 404 /error.php
ErrorDocument 500 /error.php    
## doesn't work for me
##FileETag MTime Size
##ExpiresActive on
##ExpiresDefault "access plus 86400 seconds"
# 1 WEEK
<FilesMatch "\.(jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
# 2 DAYS
<FilesMatch "\.(xml|txt|css|js)$">
Header set Cache-Control "max-age=172800, proxy-revalidate"
</FilesMatch>
# 1 MIN
<FilesMatch "\.(html|htm|php)$">
Header set Cache-Control "max-age=60, private, proxy-revalidate"
</FilesMatch>
<ifmodule mod_deflate.c="">
<filesmatch ".(js|css)$"="">
SetOutputFilter DEFLATE
</filesmatch>
</ifmodule>

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond  %{QUERY_STRING} !^myvar=0
RewriteCond %{REQUEST_URI} !\..*$
RewriteRule ^([^/]*)/?$ /$1.php?myvar=0 [QSA,L]

答案 1 :(得分:1)

尝试以下规则,使其按照您的要求运作,

RewriteCond %{REQUEST_URI} (.*)(\.php|\/)$
RewriteRule (.*)$ %1 [R=301,L]

如果它不起作用,请告诉我。