Htaccess Redirect from subdirectory to root

馋奶兔 提交于 2020-01-26 04:20:09

问题


I'm looking for a htaccess code to redirect my url's like this :

http://01.mydomain.com/subdir/xyz [OR]
http://www.01.mydomain.com/subdir/xyz [OR]
http://02.mydomain.com/subdir/xyz [OR]
http://www.02.mydomain.com/subdir/xyz
TO : http://www .mydomain.com/xyz

and in this case xyz is dynamic and could be any value. and subdir is constant


回答1:


Assuming subdir is constant, the following is one way:

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^01.mydomain.com [OR]
RewriteCond %{HTTP_HOST} ^www.01.mydomain.com [OR]
RewriteCond %{HTTP_HOST} ^02.mydomain.com [OR]
RewriteCond %{HTTP_HOST} ^www.02.mydomain.com
RewriteRule ^subdir/(.*)$ http://www.mydomain.com/$1 [L,R=301]



回答2:


RewriteRule ^/subdir/(.*)/?$ /$1 [R=301,L]


来源:https://stackoverflow.com/questions/13018031/htaccess-redirect-from-subdirectory-to-root

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