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

有帮助吗?

解决方案

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]
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top