kylex
kylex

Reputation: 14416

Redirect all subdomains to a subfolder, excluding www

Here's what I have so far, and it works, but I want to exclude (www)

RewriteBase /
RewriteCond %{HTTP_HOST} [^.]+\.example\.com.*$
RewriteRule (.*) sub/$1 [L]

EDIT:
For example jason.example.com would redirect to example.com/sub/
BUT www.example.com would stay on the root directory: example.com/

Upvotes: 1

Views: 108

Answers (2)

Jon Lin
Jon Lin

Reputation: 143906

If you want the rule not to be applied when the hostname starts with www or doesn't have a subdomain at all, then you can exclude it by modifying your regex:

RewriteBase /
RewriteCond %{HTTP_HOST} ^((?!www).*)\.example\.com$ [NC]
RewriteRule (.*) sub/$1 [L]

Upvotes: 2

JuanKB1024
JuanKB1024

Reputation: 344

I would recommend you use Virtual Hosts in Apache instead of the configuration file.

Here is a cool tutorial about it:

http://www.thegeekstuff.com/2011/07/apache-virtual-host/

Cheers!

Upvotes: 0

Related Questions