homepage Welcome to WebmasterWorld Guest from 107.20.109.52
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Mod-rewrite redirect doesn't work
Do I need a DNS entry too?
fanzila




msg:1506272
 3:46 pm on May 7, 2002 (gmt 0)

Hi,

I make apache 1.3.24 with all module on a RH7.2.
I want to redirect the url www.server.com/~user to www.user.server.com
so i write in httpd.conf :

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.[^.]+\.server\.com$
RewriteRule ^(.+) %{HTTP_HOST}$1
[C]
RewriteRule ^www\.([^.]+)\.server\.com(.*) /home/$1/www/$2

and I have

UserDir /home/*/www

<VirtualHost xxx.xxx.xxx.xxx>
ServerAdmin webmaster@serveur.com
DocumentRoot /home/xxx/www
ServerName www.serveur.com
ServerAlias serveur.com
CustomLog logs/serveur-access_log combined
ScriptAlias /cgi-bin/ /home/xxx/cgi-bin/
</VirtualHost>

but when I go to www.user.server.com apache display the document root of the server.
I think I must have a DNS entry in the DNS server for www.user.server.com
But what is the file and the line to write ?
Thanks for your responses and excuse me for my bad english ;)

Pierre

 

DaveAtIFG




msg:1506273
 6:05 pm on May 9, 2002 (gmt 0)

Welcome to wmw fanzila, we're pleased to have you join us!

I can do a few tricks with mod_rewrite but your question is beyond my meager talents. I am making an effort to find an expert or two that can help you so please be patient! :)

bird




msg:1506274
 7:48 pm on May 9, 2002 (gmt 0)

I'm not exactly sure which way you're trying to go here.

Your DNS question actually makes me think that you might be confusing internal rewrites (done transparently by the server) and external redirects (executed client side by the browser).

Using the %{HTTP_HOST} in the subsitution part of a RewriteRule implies a browser redirect, which would need the [R] flag. Adding the host name to the path for the server in an internal rewrite serves no useful purpose.

There's also the problem that the string you're trying to match with the next rule actually only contains the path component of the URL. Your "^www\.([^.])+\.server\.com(.*)" pattern will therefore never match. To get at the user part of the request you can use a %# type reference to a group in the last RewriteCond pattern instead.

So, what I would try looks something like this (untested):

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.([^.]+)\.server.com$ [NC]
RewriteRule ^(.*)$ /home/%1/www/$1 [L]

The [NC] flag for the RewriteCond makes the matching case-insensitive. This *may* lead to trouble later, because your user directories are case sensitive. If you don't use this flag, then any visitor specifying "...COM" instead of "...com" will get past this ruleset, probably seeing your document root again. You could try to use eg. the "tolower" mapping function, but I'm not sure if I understand its use correctly yet. Something like /home/${tolower:%1}/www/$1 might do the trick.

The [L] flag for the RewriteRule stops mod_rewrite processing at that point. This saves some CPU time, but if you have other rules further down that are supposed to modify the result of this one, then you'd have to remove it.

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