1

I want to do those classical 301 redirects:

  • Prepend "www" if there is not.
  • Add "/shop/" directory if there is not.
  • In both cases, I want to mantain the file requested and possible parameters.

And also (this is the point) I want to avoid multiple redirects when http://myhost.com is requested:

  1. 301 -> http://www.myhost.com
  2. 301 -> http://www.myhost.com/shop/

I want only 1 redirect. How can I do it in the simplest way?

Katapofatico
  • 750
  • 1
  • 10
  • 29

1 Answers1

1

You can use this :

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www [OR]
RewriteCond %{REQUEST_URI} !^/shop
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$
RewriteRule ^ http://www.%1/shop%{REQUEST_URI} [NE,L,R=301]
Amit Verma
  • 40,709
  • 21
  • 93
  • 115