I need to redirect from http://example.com/
to http://example.com/index.php
.
我需要从http://example.com/重定向到http://example.com/index.php。
3 个解决方案
#1
15
Use this:
用这个:
DirectoryIndex index.php
#2
2
Try this:
尝试这个:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^$
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule ^$ http://example.com/index.php [L,R=301]
#3
0
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.
这还保留了任何可能的现有查询字符串参数。
#1
15
Use this:
用这个:
DirectoryIndex index.php
#2
2
Try this:
尝试这个:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^$
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule ^$ http://example.com/index.php [L,R=301]
#3
0
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.
这还保留了任何可能的现有查询字符串参数。