简体   繁体   中英

htaccess - redirect entire site wild card not working

I have the following in my htaccess file

RewriteCond %{HTTP_HOST} ^olddomain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.olddomain\.com$
RewriteRule ^(.*)$ "http\:\/\/www\.newdomain\.com\/$1" [R=301,L]

From my understanding this should redirect any url to the new domain version

For instance

http://www.olddomain.com redirects to http://www.newdomain.com just fine

but

anything else like http://www.olddomain/1/2/3 does not redirect to http://www.newdomain.com/1/2/3

Try this code:

RewriteEngine On

RewriteCond %{HTTP_HOST} olddomain\.com$ [NC]
RewriteRule ^ http://www.newdomain.com%{REQUEST_URI} [R=301,L,NE]

This will redirect all wildcard http://www.olddomain.com/1/2/3 URIs to http://www.newdomain.com/1/2/3

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