简体   繁体   中英

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. 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:

<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.

<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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM