homepage Welcome to WebmasterWorld Guest from 54.161.175.231
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

This 32 message thread spans 2 pages: < < 32 ( 1 [2]     
automatically routing subdomains via mod_rewrite?
instead of hand-coding each rule for each sub
amznVibe




msg:1520372
 4:54 am on Jan 12, 2003 (gmt 0)

I've read a few threads on here about using mod_rewrite
for pseudo subdomains but I am looking to produce a superior
routine that doesn't require hand coding of each sub into .HTACCESS
Need some help from the mod_rewrite Gurus!

I've gotten my host to turn on wildcard DNS for me and the follow code definitely works properly:

RewriteCond %{HTTP_HOST} images\.mydomain\.com [NC]
RewriteCond %{REQUEST_URI}!^/images/.*
RewriteRule (.*)/images/$1[L]

So if [images.mydomain.com...] is entered,
it transparently uses [mydomain.com...]

Now to attempt automatic mode, this does NOT work, help!

RewriteMap lowercase int:tolower
RewriteEngine on

RewriteCond ${lowercase:%{HTTP_HOST}}!^$
RewriteCond ${lowercase:%{HTTP_HOST}}!^www\.mydomain.com$

RewriteCond ${lowercase:%{HTTP_HOST}} ^(www\.¦)([^.]+)\.mydomain\.com$
RewriteRule ^(.+) ${lowercase:%{HTTP_HOST}}$1 [C]
RewriteRule ^(www\.¦)([^.]+)\.mydomain\.com.*) /$2$3 [L]

 

andreasfriedrich




msg:1520402
 5:57 pm on Feb 19, 2003 (gmt 0)

>>Will it help to enable RewriteLog?

Yes it would. But let me first check the rules on my server. Once they work for me you could try them on your server. If they do not work there, then enabling RewriteLog [httpd.apache.org] will help indeed.

>>And what RewriteLogLevel is safe to use without
>>slowing down the serve?

RewriteLogLevel [httpd.apache.org] below 3 are ok. But they will not always yield enough information about what´s going on.

Let me finish dinner and I´ll test the rules ASAP ;)

Andreas

andreasfriedrich




msg:1520403
 7:35 pm on Feb 19, 2003 (gmt 0)

Now I´m really confused. The rules no longer prevent recursion. This entry in my rewritelog is what´s at the heart of the problem and what is really baffling me.

RewriteCond: input='aaron<->aaron' pattern='!^(.*)<->\1$' => matched

What is says is basically that what is on the left hand side of the <-> is not the same as what´s on the right hand side. BUT IT IS THE SAME!

Perl [perl.com] is on my side.

Perl [perl.com] -e '$_="aaron<->aaron"; print "+" if /^(.*)<->\1$/;'

will print +. I know that is no real proof since Perl [perl.com] uses Perl [perl.com] regular expressions while mod_rewrite [httpd.apache.org] uses POSIX regular expressions but I´m using only a subset that is equal in both.

And what´s really strange is that the even the earlier code that worked for amznVibe and me no longer works :o

I switched from Redhat to Debian and Apache [httpd.apache.org] 1.27 to 1.26 but never expected that there were such big differences.

RewriteEngine On
# Rewrite only when Host is not empty
RewriteCond %{HTTP_HOST}!^$
# Rewrite only when Host is not main domain
# Delete if there is no main server that is not subject to rewriting
#RewriteCond %{HTTP_HOST}!^server$ [NC]
# Extract domain (%1), tld (%2) and first two path elements (%3)
RewriteCond %{HTTP_HOST}<->%{REQUEST_URI} \.([^.]+)\.([^.]+)<->/([^/]+)?/?([^/]+)? [NC]
# Rewrite only when "tld/domain" not equal to first two path elements
RewriteCond %2<->%3!^(.*)<->\1$ [NC]
RewriteCond %1<->%4!^(.*)<->\1$ [NC]
# Rewrite to /subdomain/request
RewriteRule ^(.*) /%2/%1/$1 [L]

This code does work except that it will cause an endless loop. You might want to try it and see whether it goes into a loop. It shouldn´t and didn´t in my earlier code when testing on Redhat.

Andreas

This 32 message thread spans 2 pages: < < 32 ( 1 [2]
Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved