Forum Moderators: phranque

Message Too Old, No Replies

Using both %{REQUEST_URI} and %{HTTP_HOST}

         

ebloggy

4:45 pm on Jul 16, 2004 (gmt 0)

10+ Year Member



I have used mod_rewrite to direct [username.gnsite.com...] to a user's account, whose username is 'username'.

Assuming that [username.gnsite.com...] or [username.gnsite.com...] is used, how should I write in .htaccess such that message 3 by 'username' is shown?

That means, when [username.gnsite.com...] is used, .htaccess should first extract 'username' and then extract '3' and use them both for redirection (to account.php?user=username&message=3)

Currently, this is what I have to redirect [username.gnsite.com...] to account.php?user=username

RewriteCond %{HTTP_HOST}!^www\.gnsite\.com [NC]
RewriteCond %{REQUEST_URI} ^/?$
RewriteRule ^(.*) %{HTTP_HOST} [C]
RewriteRule ^([^\.]+)\.gnsite\.com account.php?user=$1 [NC,L]

Any help would be greatly appreciated. Thanks in advance.

jdMorgan

8:15 pm on Jul 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You'll need to use a back-reference to the RewriteCond pattern match, and chaining is not required in this case.

Rewrite [www.]<username>.example.com/<msg_number>/ --> /account.php?user=<username>&message=<msg_number>
(The leading "www." in the requested domain is optional -- some people think they have to type it, so we'll allow it.)


RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} ^(www\.)?(.+)\.example\.com
RewriteRule ^([0-9]+}/$ /account.php?user=%2&message=$1 [L]

This code is for use in .htaccess. For use in httpd.conf, add a leading slash to the RewriteRule pattern.

Jim

ebloggy

1:29 am on Jul 17, 2004 (gmt 0)

10+ Year Member



Thanks!