Reputation: 91
I'm stuck. I don't know much about htaccess and I'm just winging it. Can someone look at the code and tell me what's wrong with it. I simply want to redirect an old site to a new site and the only changes are the domain, a variable that will match between old/new pages and an added word to the permalink structure.
Here's some of the variations I've tried so far:
Options +FolowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^.*domain.com/matchingword1-(.*)-matchingword2-matchingword3/ [NC]
RewriteRule ^(.*)$ http://www.newdomain.com/matchingword1-$1-matchingword2-differentword-matchingword3/ [R=301,L]
Options +FolowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^.*domain.com/matchingword1-(.*)-matchingword2-matchingword3/ [NC]
RewriteRule ^(.*)$ http://www.newdomain.com/matchingword1-%1-matchingword2-differentword-matchingword3/ [R=301,L]
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^domain\.com/matchingword1-(.*)-matchingword2-matchingword3/$ http://www.newdomain.com/matchingword1-\$1-matchingword2-differentword-matchingword3/\ [R=301? [R=301,NE,NC]
The section (. *) will be the exact same as $1 on the new domain but the permalink is a little different. The part of the permalink that is (. *) will be anything from multiple words and numbers.
For example: matchingword1-this-page-is-1st-matchingword2-matchingword3/ redirects to newdomain dot com/matchingword1-this-page-is-1st-matchingword2-differentword-matchingword3/
Upvotes: 0
Views: 1113
Reputation: 143906
The rewrite condition for HTTP_HOST
is what is passed in the request's "Host:" header, which only contains the host (and in some cases a port). The Request URI isn't part of HTTP_HOST
. Try something like this:
RewriteCond %{HTTP_HOST} ^.*domain.com [NC]
RewriteRule ^matchingword1-(.*)-matchingword2-matchingword3/ http://www.newdomain.com/matchingword1-$1-matchingword2-differentword-matchingword3/ [R=301,L]
The last set doesn't look like it'll work at all.
Edit: comments won't let me insert code
If you want to redirect EVERYTHING, you should use mod_alias' RedirectMatch:
RedirectMatch ^(.*)$ http://www.newdomain.com/$1
If you are serving the directory on the same instance of apache (as in, domain.com and newdomain.com is actually the same server serving from the same directory), then you need to rewrite. Something like this:
RewriteCond %{HTTP_HOST} ^.*domain.com [NC]
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R=301,L]
Upvotes: 1