如何允许 .php、尾部斜杠和无尾部斜杠?

发布于 2024-10-31 02:49:43 字数 1155 浏览 1 评论 0原文

如何允许 .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]

How do I allow .php, trailing slash, and no trailing slash?

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]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

最终幸福 2024-11-07 02:49:43

尝试使用这个修改后的 .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]

Try this modified .htaccess file instead:

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]
无法回应 2024-11-07 02:49:43

尝试以下规则,使其根据您的要求工作,

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

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

Try below rules to make it work according to your requirement,

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

Let me know in case it doesnt work..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文