Reputation: 253
If I use anything in wildcard it's redirecting me to example.com/shop
. But what I want is when someone uses anything.example.com/code
he redirects to example.com/shop/code
. The current setting is redirecting me to example.com/code/shop
if I use anything after the trailing slash in my case it's code
.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^[^.]+\.(example\.com)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI}/shop [R=301,L,NE]
Upvotes: 1
Views: 131
Reputation: 45829
You would seem to just need to reverse the %{REQUEST_URI}/shop
part in the substitution string... (?)
For example:
RewriteCond %{HTTP_HOST} ^[^.]+\.(example\.com)$ [NC]
RewriteRule ^ http://%1/shop%{REQUEST_URI} [R=301,L,NE]
The REQUEST_URI
server variable contains the full URL-path (only) that the user requested, including the slash prefix.
You will need to clear your browser cache before testing. (Preferably test first with 302 temporary redirects to avoid caching issues.)
Upvotes: 1