如何将我网站上的所有流量重定向到主页?
我们正在为客户重新设计网站。在他们当前的托管上,我们删除了他们的旧网站,并建立了一个登陆页面(http://norbutconstruction.com/)作为他们的主要索引。
这是我在 .htaccess 文件中执行重定向的代码:
<IfModule mod_rewrite.c>
#Redirect all of the traffic to the temporary landing page
RewriteEngine on
RewriteRule (.*) /index.php [R=302,L]
</IfModule>
当我尝试访问 Google 已索引的页面 (http://www.norbutconstruction.com/contact-us) 时,这会导致无限循环。只要我一直在使用 .htaccess 文件,我似乎就记得编写会导致无限循环的规则。我知道这应该是非常简单的事情,但我什至找不到如何做到这一点的示例。
是否有人对如何使此代码正常工作有任何建议,或者对如何避免 .htaccess 重定向中的无限循环有任何一般建议?我似乎总是在这些方面遇到麻烦。
提前致谢!
最佳答案
试试这个:
<IfModule mod_rewrite.c>
#Redirect all of the traffic to the temporary landing page
RewriteEngine on
RewriteCond %{REQUEST_URI} !.*index\.php
RewriteRule (.*) /index.php [R=302,L]
</IfModule>
关于.htaccess - 如何使用 .htaccess 将所有流量 302 重定向到主页?避免无限重定向循环?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5160365/