Nojan
Nojan

Reputation: 913

Htaccess Redirect from subdirectory to root

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

Upvotes: 0

Views: 4959

Answers (2)

kalpaitch
kalpaitch

Reputation: 5261

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

Upvotes: 1

Jason McCreary
Jason McCreary

Reputation: 72961

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]

Upvotes: 2

Related Questions