问题
I'm trying to figure out a rewrite so as to redirect a directory and all of it's files & subdirectories from one domain to another.
Here is what I would like to achieve:
olddomain.com/oldfolder/*
to
http://newdomain.com/newfolder/*
Currently I am using the following:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.olddomain\.com$
RewriteRule (.*) http://newdomain.com/newfolder/$1 [L,R=301]
This works for www.olddomain.com but not also for olddomain.com. What's the best way to achieve this?
Thanks so much for your help.
回答1:
Replace your code with this:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC]
RewriteRule ^oldfolder/(.*)$ http://newdomain.com/newfolder/$1 [L,R=301,NC]
来源:https://stackoverflow.com/questions/18408416/redirecting-folder-from-one-domain-to-another-using-htaccess-301-redirect