Thursday, November 23, 2017

linux - 301 Redirect issue when term in new and old URL



We are trying to create a set of 301 redirects where the exact string from the old URL is also present in the same position in the new URL. See the example below:



Old URL



http://www.domain.com/foobar



New URL



http://www.domain.com/foobar/i55


We've tried a standard 301 redirect like this:



Redirect 301 /foobar$ http://www.domain.com/foobar/i55



This doesn't work and causes a 404:



File does not exist: /home/domain/public_html/foobar


Should we be looking at rewrite rules instead or can this be fixed by just adjusting the 301 rule?



Thanks.



Answer



You need to use the RedirectMatch in mod_alias i.e:



RedirectMatch 301 /foobar$ http://www.domain.com/foobar/i55


EDITED BASED COMMENT


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...