apache仅重定向根斜杠主页

rub*_*o77 0 redirect apache-2.4

我只需要在 Apache 2.4 中将http://example.org/重定向到http://www.something-other.org/ 。

只是主页。没有其他的。即http://example.org/?page=bloghttp://example.org/contact.html不应重定向。

我所能找到的就是将页面完全重定向到另一个网站,例如:

Redirect "/" "http://www.something-other.org/"
Run Code Online (Sandbox Code Playgroud)

这更好一点:

RewriteEngine On
RewriteRule ^/$ http:// www.something-other.org/ [L,R=301]
Run Code Online (Sandbox Code Playgroud)

它仅重定向主页,而且如果有查询字符串也会重定向。

rda*_*rda 6

您需要使用mod_rewrite

RewriteEngine On
RewriteCond "%{QUERY_STRING}" "^$"
RewriteRule "^/$" http://something-other.org/ [L,R=301,QSD]
Run Code Online (Sandbox Code Playgroud)

QSD标志丢弃查询字符串。

启用mod_rewrite并重新启动apache

root@host:~# a2enmod rewrite
root@host:~# service apache2 restart
Run Code Online (Sandbox Code Playgroud)


归档时间:

查看次数:

9388 次

最近记录:

8 年,8 月 前