how to redirect all subdomains to another with parameter after the trailing slash using htaccess?

和自甴很熟 提交于 2021-01-28 19:04:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!