将所有内容重定向到 public_html

Redirect everything to public_html

我不敢相信我自己找不到解决方案,但就是这样。我希望 Apache 将 example.com/page.php 之类的每个请求重定向到 example.com/http/page.php。我在 Internet 和 Whosebug 上找到了很多选项,但其中 none 有效。现在我明白了:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule (.*) http://example.com/http/ [R=301,L]
RewriteRule ^$ http [L]

这会将 example.com 重定向到 example.com/http 但是 example.com/some_page.php 之类的所有内容都会引发 404 错误。其他选项要么根本不起作用,要么做同样的事情。 在 CentOS 上是 Apache/2.2.22,如果这很重要的话。

试试这条规则:

RewriteEngine on

RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(?!http/).*\.php$ /http%{REQUEST_URI} [R=301,L,NE,NC]

确保在测试之前清除浏览器缓存。