11

我需要从 重定向http://example.com/http://example.com/index.php

4

4 回答 4

20

用这个:

DirectoryIndex index.php
于 2012-04-16T14:16:20.457 回答
4

试试这个:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} ^$
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule ^$ http://example.com/index.php [L,R=301]
于 2012-04-16T14:16:32.650 回答
1

只是添加我自己的解决方案,因为迈克尔的答案对我不起作用,我做了类似的事情:

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]

这也保留了任何可能的现有查询字符串参数。

于 2018-08-13T15:15:53.313 回答
0

添加到上面@Uwe Keim 的 回答中,我在 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]
于 2021-06-09T17:45:49.590 回答