0

Trying to do global 301 redirects in .htaccess file from:

domain.com/old/name-of-post

to

newdomain.com/new/name-of-post

The last segment of the url is dynamic based off the post title "name-of-post" and remains the same on both sites but the "old/new" and "domain.com/newdomain.com" have changed. My goal is to not have to go through and add hundreds of individual redirects.

Any insight on this anyone?

0

You could use mod_rewrite with some regex like this:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^/old/(.*)/?$ http://newdomain.com/new/$1 [R=302,L,NC]
</IfModule>

This would go in the .htaccess file in the olddomain.com document root.

I'd suggest leaving it as a 302 until you are sure it's having the desired effect, as most browsers will cache 301's and then not look at your .htaccess anymore just follow the cached routes - which can be tricky to clear (you definitely don't want to be explaining how to clear them to end users!).

Also, this isn't really a WP question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.