user2569521
user2569521

Reputation: 1

.htaccess redirect/rewrite from one url to another, and subpages to other pages

I'm having some difficulty trying to get a correct rewrite/redirect that will do what I want and I'm wondering if it's even possible.

I have this rewrite setup:

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

This works great to take all requests from olddomain.com/whatever and rewrite them to my new main url. However, I also would like to be able to take 10 or 15 of the most popular "old" urls and rewrite/redirect them to the new location on the new url. My directory structure changed with the changeover to new url, so all the new urls are different and things are located in different places. Is it possible to have all traffic from the old domain redirected to the new domain AND specify a few old urls to redirect to new urls on the new domain?

I hope this is clear enough and I'm hoping someone can assist me. Thanks for your time!

Tom

Upvotes: 0

Views: 1117

Answers (1)

jrthib
jrthib

Reputation: 1319

Here's a solution:

.htaccess for old domain

Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]

In the above, you could place redirect rules to catch certain pages and forward them to their new location, like this:

Redirect 301 /2012/05/old-post http://www.newdomain.com/old-post

Be sure to place the redirect directives above the rewrite rule that catches everything else.

.htaccess for new domain

Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.[a-z-]+\.[a-z]{2,6} [NC]
RewriteCond %{HTTP_HOST} ([a-z-]+\.[a-z]{2,6})$     [NC]
RewriteRule ^/(.*)$ http://%1/$1 [R=301,L]

Found this solution on: https://forums.digitalpoint.com/threads/htaccess-redirect-all-traffic-to-another-site.867280/

I've done similar things, so hopefully it helps.

Upvotes: 1

Related Questions