Forum Moderators: phranque
I'm trying to work with subdomains. I have DNS with wildcard subdomains, everything is up. I'm using mod_rewrite to rewrite the url to be a subdomain like this:
RewriteEngine On
Options +FollowSymlinks
RewriteBase /
RewriteCond %{HTTP_HOST} subdomainname.mydomain.net
RewriteCond %{REQUEST_URI}!main/archives/subdomainame
RewriteRule ^(.*)$ main/archives/subdomainname/$1 [L]
Now here is the problem: I have a ton of subdomains I wish to add. I was wondering; instead of adding a whole new block of that code every single time to my htaccess file is there any way to have it automatically pick it up using wildcards? ex, a theoretical code for wildcards:
RewriteEngine On
Options +FollowSymlinks
RewriteBase /
RewriteCond %{HTTP_HOST} *.mydomain.net
RewriteCond %{REQUEST_URI}!main/archives/*
RewriteRule ^(.*)$ main/archives/*/$1 [L]
Is there a way to do this?
Thanks for your time.
The following code will work assuming two things:
1) You do not wish to make a 'subdomain subdirectory' for the 'www' subdomain.
2) *All* files in /main/archives belong to subdomains. If not, you will need to create a new subdirectory and make it so.
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/main/archives/
RewriteCond %{HTTP_HOST} !^www\.mydomain\.net
RewriteCond %{HTTP_HOST} ^([^.]+)\.mydomain.net
RewriteRule (.*) /main/archives/%1/$1 [L]
Jim