Reputation: 11
Maybe I just don't know how to ask the question to find the answer but what I want to do is an .htaccess redirect from an old URl, shop.nilandsplace.com/camp to nilandsplace.com/store/camping. Not to make it more difficult, but I would like to know what it is that I am doing so I can learn this
Upvotes: 0
Views: 1293
Reputation: 1166
Try this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^shop.nilandsplace.com$
RewriteRule ^camp(.*)$ http://nilandsplace.com/store/camping$1 [R=301,L]
The top line turns on the rewrite engine. We need to do this before rewriting any URLs.
The second line checks that we're visiting the shop.nilandsplace.com
domain.
The third line redirects any requests from /camp
to http://nilandsplace.com/store/camping
. The bit in brackets at the end of the third line tells Apache to make this a 301 redirect (so search engines know the page has moved), and to do the redirect straight away, bypassing any upcoming rewrite rules for this request.
The code will also redirect subdirectories of camp (anything after camp), for example shop.nilandsplace.com/camp/tent-poles
> nilandsplace.com/store/camping/tent-poles
.
You can learn more about the mod_rewrite
module (which powers the rewrite engine) on the Apache Docs.
Upvotes: 1