Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I had recently moved all the content on my website from being in the www.mysite.com/shop directory to being in the root directory. This means that I needed to redirect any request to visit a page with the /shop directory back to the same page in the root directory eg.

www.mysite.com/shop/categories/washroom

to

www.mysite.com/categories/washroom

This needed to happen with all pages in my site that were previously using the /shop directory.

I was given a solution on here which was:

RedirectMatch (^/shop/)(.*) http://www.mysite.com/$2

and it works perfectly however now I have had to switch back to using our old version of our software which is located at the /shop directory so I need the complete opposite redirect now eg.

www.mysite.com/categories/washroom 

to

www.mysite.com/shop/categories/washroom 

Can anyone help me please?

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

You could try:

RedirectMatch (^/categories/washroom/)(.*) http://www.mysite.com/shop/categories/washroom/$1

Does that work?

share|improve this answer
    
I just tried and it didn't work unfortunately. –  user43652 Jun 6 '10 at 23:53
    
sorry replace the $1 with a $2 –  okonomiyaki Jun 7 '10 at 0:28
    
Thanks for your reply, I just checked it again and it still doesn't work. I need to redirect all of our pages to the same page in the /shop directory so i'm not sure that having a line of code for each page will work because there are a large number of pages to be redirected. –  user43652 Jun 7 '10 at 0:56
    
Hmmm.. it works for me. I go to: x.x.x.x/categories/washroom and i get redirected to: x.x.x.x/shop/categories/washroom Even works when i put in: x.x.x.x/categories/washroom/blah.html redirects me to: x.x.x.x/shop/categories/washroom/blah.html –  okonomiyaki Jun 7 '10 at 3:07
    
I still didn't get it to work with the categories pages yet however it is working now for the products pages using this code: RedirectMatch (^/products/)(.*) mysite.com/shop/products/$2 So, mysite.com/products/product1.html redirects to mysite.com/shop/products/product1.html Which solves the majority of my problem because until our site gets upgraded and is working properly we need visitors that are coming from search engines to go to the correct place. Thanks for your persistance with helping me fix this. –  user43652 Jun 7 '10 at 3:21
add comment

Reverse your logic:

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/shop
RewriteRule ^/(.*)$ http://%{SERVER_NAME}/shop/$1 [L,R]
share|improve this answer
    
Thanks for your reply, I have solved my original problem with the answer above however your reply will be useful for future reference. –  user43652 Jun 7 '10 at 6:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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