![](/img/trans.png)
[英]Apache: Using VirtualHost redirect to URL with RewriteCond applied?
[英]How to redirect a web page while not changing the URL (using Apache VirtualHost)
我正在Apache Web服务器中设置虚拟主机,并且已经有一些规则,可以执行从一个URL到另一个URL的简单301重定向。 但是,现在有人问我是否可以编写一个重定向到另一个页面的规则,同时保持URL不变,所以我尝试了以下方法:
<VirtualHost *:80>
ServerName ZZZ.com
ServerAlias YYY.com ZZZ.com
Redirect / YYY.com
</VirtualHost>
和这个:
<VirtualHost *:80>
ServerName ZZZ.com
RewriteEngine on
RewriteRule ^/(.*) YYY.com/$1 [R]
</VirtualHost>
我对他们的期望也没有。 他们在我看来错了,但我只是在任何地方都找不到任何有用的信息。 我看过http://httpd.apache.org/docs/2.4/vhosts/examples.html和http://httpd.apache.org/docs/current/mod/mod_rewrite.html-他们都不是有帮助的。
<VirtualHost *:80>
ServerName YYY.com
ServerAlias ZZZ.com
RewriteEngine on
RewriteCond %{HTTP_HOST} !^yyy\.com$ [NC]
RewriteRule (.*) YYY.com$1 [R=302,L]
</VirtualHost>
您错过了阻止其重定向正确URL的条件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.