.htaccess redirect root to index.php

2020-03-01 15:53发布

I need to redirect from http://example.com/ to http://example.com/index.php.

3条回答
Lonely孤独者°
2楼-- · 2020-03-01 16:36

Try this:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} ^$
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule ^$ http://example.com/index.php [L,R=301]
查看更多
成全新的幸福
3楼-- · 2020-03-01 16:43

Use this:

DirectoryIndex index.php
查看更多
爷的心禁止访问
4楼-- · 2020-03-01 16:56

Just to add my own solution, since the answer of Michael did not work for me, I did something like:

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]

This also preserves any possible existing query string parameters.

查看更多
登录 后发表回答