重定向* .PHP清洁网址重定向* .PHP清洁网址(Redirect *.php to clean

2019-05-12 08:04发布

我的htaccess完全不是那么回事:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.php$ /blah/$1 [R=301,L]
RewriteRule ^(.*)$ /blah/index.php/$1 [L]

基本上/blah/about.php应该重定向到/胡说/约

我使用笨所以最后一行需要处理的URL。

重定向工作正常,但我在/胡说得到一个内部服务器错误/约

**编辑 - 错误日志:

请求超过了10个内部重定向的上限,由于可能的配置错误。 使用“LimitInternalRecursion”如果需要增加限制。 使用“LogLevel的调试”,以获得回溯。

Answer 1:

我想你只需要改变你的最后一行是:

RewriteRule ^(.*)$ /blah/index.php?/$1 [L]

我有一个笨没有具体的经验,但总体构架希望通过中央控制器(的index.php)推送的所有请求,然后从那里内部解析请求的URL。

编辑:刚刚更新我的答案从这里的例子: http://codeigniter.com/wiki/mod_rewrite/ ,应该是笨想要怎样的。

更新:你或许应该复制你的RewriteConds第二重写规则,它们只适用于第一种:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.php$ /blah/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /blah/index.php/$1 [L]


Answer 2:

感谢@Cryo对他的帮助,这是修复:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)\.php$ /blah/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ /blah/index.php/$1 [L]


Answer 3:

关于什么:

RewriteRule ^(.*)(\.php)?$ /blah/index.php/$1 [L]

并取出前行。

还要确保/blah/about.php不存在。



Answer 4:

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)\$ $1.php [NC]


文章来源: Redirect *.php to clean URL