HTAccess 301 Redirects - Need Help!

-Jericho-

Elite Member
Joined
Jan 10, 2010
Messages
2,831
Reaction score
1,739
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 one of the variations I've tried so far:
Code:
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]
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/
 
Last edited:
Are you creating a list of rules or wanting to create one conditional rule?

If you are happy to have a list of rules you can create the new URLs in excel using a find and replace, then use
Code:
http://seo-website-designer.com/HtAccess-301-Redirect-Generator
to create the file.

If you have gazillions of pages and want to create a conditional rule then I think you might need to use

Code:
RewriteCond %{REQUEST_URI}

instead of

Code:
RewriteCond %{HTTP_HOST}
 
I have around 12,000 pages to redirect. So doing them one by one is a pain and the site has been taken down for sometime. I'm simply trying to recapture the backlinks from it.

The request uri didn't work either.
 
It's not because you're using $ instead of % is it?

(I always get confused - this might just be for {query_string}...)

Code:
Options +FolowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^.*domain.com/matchingword1-(.*)-matchingword2-matchingword3/ [NC]
RewriteRule ^(.*)$ http://www.newdomain.com/matchingword1-[B]%1[/B]-matchingword2-differentword-matchingword3/ [R=301,L]
 
Ok I think you do need a query string, I'm just not sure of the syntax.

Something like

Code:
RewriteCond %{QUERY_STRING}  ^$
RewriteRule ^domain\.com/matchingword1-(.*)-matchingword2-matchingword3/$ http://www.newdomain.com/matchingword1-\$1-matchingword2-differentword-matchingword3/\ [R=301? [R=301,NE,NC]
 
there you go:
Code:
Options +FolowSymlinks RewriteEngine on RewriteCond %{HTTP_HOST}%{REQUEST_URI} ^.*domain.com/matchingword1-(.*)-matchingword2-matchingword3/ [NC] RewriteRule ^(.*)$ http://www.newdomain.com%{REQUEST_URI} [R=301,L]

now rep me up :D
 
Back
Top