Forum Moderators: phranque

Message Too Old, No Replies

Redirect Internal URLS and NOT the Homepage

         

SerpsGuy

10:42 pm on Oct 12, 2014 (gmt 0)

10+ Year Member



I asked on stackoverflow, but I was marked as a duplicate question - despite the duplicate question having received no valid answers.


I would like my landing page to stay the same. So loading www . sample . com/ will not redirect anything. However, anything after that, such as www . sample . com/page-link/ will redirect to the new sitewww . newsite . com/page-link/.

I tried this

RedirectMatch 301 /(.*) http : //www . newsite . com/

But it redirects the homepage. Again, the homepage (root url) of www.sample.com should load as it normally does. But any query added in the form of

permalink-here/ should be redirected. Is this something that is simple to do?

So, for this to function I need the redirect to only be called if someone is added after the trailing slash.

Example:

www . sample . com/ - DO NOT REDIRECT
www . sample . com/permalink-here/ - REDIRECT

aakk9999

11:02 pm on Oct 12, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



It would be better if you use RewriteRule and not RedirectMatch. Then you can set Rewrite Condition to say "if not exactly home page, redirect to the equivalent page on the new domain". Something like:

RewriteCond ....if request is not for home page only
RewriteRule ... redirect the complete URL path to a new domain (inclusive of append query string, if any)

This should go at the end of your redirects.

If you have any other existing redirects, they should also be changed to redirect to the new domain.

Search this forum, there are lots of examples for redirects using RewriteRule. You may start with this thread [webmasterworld.com...] whicht describes somewhat similar situation - it should get you started. Then try something and show us what you tried and you will be helped to get it right.

Use example.net and example.com instead of old/new domains to avoid autolinking.

lucy24

5:34 am on Oct 13, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



RewriteCond ....if request is not for home page only

You may not even need a Condition if you put the rule in an anomalous position: after your index.html redirects.

RewriteRule . http-etcetera


If the request has any content, it's not a request for the home page. You may need some tweaking to allow for non-page files, if any are staying behind to support the home page.