【发布时间】:2012-04-27 21:10:08
【问题描述】:
我需要从http://example.com/ 重定向到http://example.com/index.php。
【问题讨论】:
标签: apache .htaccess mod-rewrite root
我需要从http://example.com/ 重定向到http://example.com/index.php。
【问题讨论】:
标签: apache .htaccess mod-rewrite root
使用这个:
DirectoryIndex index.php
【讨论】:
DirectoryIndex 不对 SEO 场景有帮助。
试试这个:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^$
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule ^$ http://example.com/index.php [L,R=301]
【讨论】:
mod_rewrite 呢? DirectoryIndex 是这里的正确答案。
DirectoryIndex 不对 SEO 场景有帮助。
只是添加我自己的解决方案,因为 the answer of Michael 对我不起作用,我做了类似的事情:
RewriteEngine on
# These two lines redirect non-www to www.
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule (.*) https://www.example.com$1 [R=301,L]
# These two lines redirect the root to index.html.
RewriteRule ^$ /index.html [R=301,L]
RewriteRule ^/$ /index.html [R=301,L]
这也保留了任何可能的现有查询字符串参数。
【讨论】:
除了上面的@Uwe Keim'sanswer,我在 Apache 虚拟主机上设置了非 www 到 www。
.htaccess 对我有用的是:
RewriteEngine on
# Two lines to redirect from the root web directory to myfile.html.
RewriteRule ^$ /index.html [R=301,L]
RewriteRule ^/$ /index.html [R=301,L]
【讨论】: