问题
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