[英]How to redirect a web page while not changing the URL (using Apache VirtualHost)
I'm setting up Virtual Hosts in my Apache web server and already have rules in place that just do a simple 301 redirect from one URL to another. 我正在Apache Web服务器中设置虚拟主机,并且已经有一些规则,可以执行从一个URL到另一个URL的简单301重定向。 However, I've now been asked if I can write a rule that redirects to another page while keeping the URL the same and I've tried this:
但是,现在有人问我是否可以编写一个重定向到另一个页面的规则,同时保持URL不变,所以我尝试了以下方法:
<VirtualHost *:80>
ServerName ZZZ.com
ServerAlias YYY.com ZZZ.com
Redirect / YYY.com
</VirtualHost>
And this: 和这个:
<VirtualHost *:80>
ServerName ZZZ.com
RewriteEngine on
RewriteRule ^/(.*) YYY.com/$1 [R]
</VirtualHost>
Neither did what I expected of them. 我对他们的期望也没有。 They look wrong to me but I'm just not finding any helpful information anywhere.
他们在我看来错了,但我只是在任何地方都找不到任何有用的信息。 I've looked at http://httpd.apache.org/docs/2.4/vhosts/examples.html and http://httpd.apache.org/docs/current/mod/mod_rewrite.html - Neither of them were very helpful.
我看过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>
You were missing a condition to prevent it from redirecting correct urls. 您错过了阻止其重定向正确URL的条件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.