Reputation: 8050
I've moved my site with all its contents from the root to a subfolder, like
www.example.com
To
www.example.com/shop
Now, I want to redirect all old pages to the new url.
What I tried in the .htaccess of the root, but did'nt work:
RewriteEngine On
RewriteRule ^(shop)($|/) - [L] // To prevent loops
RewriteRule ^(.*)$ http://www.example.com/shop$1 [R=301,L]
But now, all old pages redirect to example.com/shop
Edit:
After it was moved, I had to add following code to the htaccess of subdirectory to make it work:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /shop/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /shop/index.php [L]
</IfModule>
Upvotes: 0
Views: 2574
Reputation: 785196
You can use this rule:
RewriteEngine On
RewriteCond %{THE_REQUEST} !/shop/ [NC]
RewriteRule !^shop/ /shop%{REQUEST_URI} [NC,R=301,L]
Upvotes: 1