Forum Moderators: phranque

Message Too Old, No Replies

Subdomains Issue

         

KlondikeBar

7:16 am on Mar 19, 2006 (gmt 0)

10+ Year Member



Hello,

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.

jdMorgan

2:21 am on Mar 21, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You're looking for a back-reference to a RewriteCond. This works in the same way as RewriteRule back-references, except that variables are desingated %1 through %9 rather than $1 through $9.

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]

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim

KlondikeBar

5:27 am on Mar 22, 2006 (gmt 0)

10+ Year Member



Thank you very much! That worked!