I have a number of URLs that I need to redirect to new locations, but there are some situations where child pages need to remain active and not redirected. For example:
/products
would redirect to http://www.newsite.com/products
/products/category1
would redirect to http://www.newsite/products/category1
But /products/specialitem
would not get redirected at all.
Is this possible with either Redirect or RedirectMatch?
Doing a Redirect 301 /products http://www.newsite.com/products
seems to affect all child pages
Thanks for any guidance!
Edit:
Using waynethec's answer, I was able to get started. But can anyone clarify why my first rule below works but the others do not?
RedirectMatch 301 ^segment-one$ http://www.google.com/
RedirectMatch 301 ^segment-one/segment-two$ http://news.google.com/
RedirectMatch 301 ^segment-one/segment-two/segment-three$ http://cnn.com/
RedirectMatch 301 ^segment-one/segment-two/segment-three/foobar$ http://gbv.com/
(By not working, I mean that I still can get to the pages, rather than them getting redirected.)
A 301 signals a permanent redirect from one URL to another, meaning all users that request an old URL will be automatically sent to a new URL. A 301 redirect passes all ranking power from the old URL to the new URL, and is most commonly used when a page has been permanently moved or removed from a website.
Use a 301 redirect . htaccess to point an entire site to a different URL on a permanent basis. This is the most common type of redirect and is useful in most situations. In this example, we are redirecting to the "example.com" domain.
Simply remove the lines from your . htaccess . In case it does not work your browser may have cached the 301 redirect, as it is meant to be permanent. Try restarting your browser or use a another browser to check whether it worked.
You should be able to use the following RedirectMatch rule:
RedirectMatch 301 ^/products$ http://www.newsite.com/products
Note that this will only redirect requests for /products, not /products/, or /products/pagename.extension.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With