我需要从重定向http://example.com/
到http://example.com/index.php
。
Answer 1:
用这个:
DirectoryIndex index.php
Answer 2:
试试这个:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^$
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule ^$ http://example.com/index.php [L,R=301]
Answer 3:
我想补充自己的解决方案,因为迈克尔的回答 ,我没有工作,我不喜欢的东西:
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]
这也保留任何可能存在的查询字符串参数。
文章来源: .htaccess redirect root to index.php