Question

I'm attempting to do a subdomain rewrite for apache using a .htaccess file.

Currently: domain.com/subdomain

Desired result: subdomain.domain.com

This is what I have so far...

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com$ [NC]
RewriteRule ^subdomain/(.*)$ http://www.domain.com/$1 [R=301,L]

Any help would be great appreciated!

Cheers, Wayne

Was it helpful?

Solution

Try this:

RewriteEngine on

RewriteCond %{HTTP_HOST} ^subdomain\. [NC]
RewriteRule . - [S=2]

RewriteRule ^subdomain/(.+)$ http://subdomain.domain.com/$1 [R=301,L]
RewriteRule ^subdomain/?$ http://subdomain.domain.com [R=301,L]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top