我已经
apt install apache2
对于100%库存ubuntu 22.04 apache2,运行a2enmod rewrite
,将这些行添加到./sites-available/000-default.conf,然后重新启动apache2。
LogLevel info ssl:warn rewrite:trace8
RewriteEngine On
RewriteRule ^$ https://www.google.com
当我在 chrome 中访问我的主机时http://192.168.56.5,我没有被重定向,日志显示(减去时间戳、ip 数字和 mod_rewrite.c(480) ):
init rewrite engine with requested uri /
applying pattern '^$' to uri '/'
pass through /
init rewrite engine with requested uri /index.html
applying pattern '^$' to uri '/index.html'
pass through /index.html
最终我想将 / 重定向到 /someplace_else/index.html ,我正在尝试重定向到 google 以避免重写循环。
我没有使用 .htaccess 文件。
我希望被重定向到谷歌,因为该片段似乎被广泛地作为答案给出。
这个: 重写规则 ^$ https://www.google.com
应该是:
RewriteRule ^/$ https://www.google.com
现在一切正常。
关键是这个 RewriteRule 在 .htaccess 和 /etc/apache/*.conf 中的行为不同