我想要的是什么:
/foo.php
在网址栏中显示/foo
/foo
重定向到/foo.php
/foo.php
/showthread.php?id=00
(/showthread?id=00
)等即使我到处都使用[L],我也会不断获得重定向循环。 我试过这些:
(1)
RewriteRule ^/forums$ forums.php [R]
RewriteRule ^/forums\.php$ forums [PT]
(2)
RewriteRule ^forums\.php/?$ forums [L,R=301]
RewriteRule ^forums/?$ forums.php
(3)
RewriteRule ^forums/?$ forums.php [L,R=301]
(4)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?([a-z/]+).php$ $1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) $1.php [L]
以上每项工作都针对个别foo.php
到foo
或foo
到foo.php
,但两者都有无限循环。
我也试过这个:
## don't touch /forum URIs
# RewriteRule ^forums/ - [L,NC]
## hide .php extension snippet
# To externally redirect /dir/foo.php to /dir/foo
# RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
# RewriteRule ^ %1 [QSA,R,L]
# To internally forward /dir/foo to /dir/foo.php
# RewriteCond %{REQUEST_FILENAME} !-d
# RewriteCond %{REQUEST_FILENAME}.php -f
# RewriteRule ^(.*?)/?$ $1.php [QSA,L]
哪个工作正常,但由于某种原因打破了很多网站功能。 (搜索栏不起作用,论坛不起作用,登录不起作用)
我需要foo.php
才能继续工作,因为MyBB使用它。
答案 0 :(得分:1)
在root .htaccess中尝试此代码:
RewriteEngine On
RewriteRule ^forums/ - [L,NC]
## hide .php extension snippet
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L]
# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]