Adi
Adi

Reputation: 4904

Redirect subdomain to subfolder of main domain with same structure

Please help me to create rewrite rule for wordpress (.htacess) that will do the following:

Redirect subdomain

AAA.site.com/BBB.html to site.com/AAA/BBB.html

Let me explain here

I have more than 100+ subdomains which i want to redirect to the "folder" with same name as subdomain using WILDCARD.

Thanks in advance

Upvotes: 0

Views: 1822

Answers (4)

Devon Grant
Devon Grant

Reputation: 1

I tried the selected solution, but it did not work for me. If it also didnt work for you try this

RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com//%1/$1

This should work for any sub-domain, just change example.com to your website name.

Upvotes: -1

DK250
DK250

Reputation: 1124

I think, this is what you are looking for:

RewriteCond %{HTTP_HOST} ^subdomain\.yourwebsite\.com$
RewriteCond %{REQUEST_URI} !^/subdomain_folder/
RewriteRule (.*) /subdomain_folder/$1

Upvotes: 0

Rápli András
Rápli András

Reputation: 3923

Try this

RewriteEngine On
RewriteCond %{HTTP_HOST} ^\(.*\)\.site\.com$ [NC]
RewriteRule ^(.*)$ http://site.com/\1/$1 [L,R=301]

Upvotes: 3

Gareth Luckett
Gareth Luckett

Reputation: 917

You can use mod_rewrite inside your .htaccess to do this.

RewriteEngine On

RewriteCond %{HTTP_HOST} ^aaa\.site\.com$ [NC]

RewriteRule ^(.*)$ http://site.com/aaa/$1 [L,R=301]

Upvotes: 0

Related Questions