重定向+重写无限循环

时间:2015-03-17 13:08:01

标签: apache .htaccess mod-rewrite redirect

对不起,我的英语不是很好,但我会试着解释一下我的问题 所以。 'index.php'是我的主要登陆页面。

一个。每个请求都应该转到index.php。 很简单。RewriteRule .* index.php [L](简化)。 因此,当我在addr栏中写“News / 123”时,index.php会处理它并向我显示新闻。它工作正常。

B中。但我还需要在addr栏中输入'/index.php'替换为'/ Home'然后 - >答:我认为它可以由Redirect /index.php /Main完成,但它会导致无限重定向循环。

任何人都可以帮我吗?

1 个答案:

答案 0 :(得分:1)

您可以在root .htaccess中使用这些规则:

DirectoryIndex index.php
RewriteEngine On

RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^index\.php$ /home [L,R=302]

# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php [L]