RewriteRule ^$ https://www.google.com :最终想要将 / 重定向到 /something_else/index.html

问题描述 投票:0回答:1

我已经

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 文件。

我希望被重定向到谷歌,因为该片段似乎被广泛地作为答案给出。

http-redirect mod-rewrite apache2
1个回答
1
投票

这个: 重写规则 ^$ https://www.google.com

应该是:

RewriteRule ^/$ https://www.google.com

现在一切正常。

关键是这个 RewriteRule 在 .htaccess 和 /etc/apache/*.conf 中的行为不同

© www.soinside.com 2019 - 2024. All rights reserved.