问题
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 its code
.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^[^.]+\.(example\.com)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI}/shop [R=301,L,NE]
回答1:
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.)
来源:https://stackoverflow.com/questions/63152513/how-to-redirect-all-subdomains-to-another-with-parameter-after-the-trailing-slas