mod_rewrite problem

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
User avatar
evilmonkey
Forum Regular
Posts: 823
Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada

mod_rewrite problem

Post by evilmonkey »

A while ago, someone on these forums (don't remeber who) was nice enough to help me with the following mod_rewrite rule. Basically, when <something>.tmeet.com is entered, I want it to forward to tmeet.com/fwd.php?username=something. The obvious exception is www, which should point to the index page. However, I recently came up on a problem: tmeet.com (with nothing in front of it) gives me a 404 page.I posted my .htaccess file below, hoping one of you gurus can provide a pointer or two. :) Thanks.

Code: Select all

RewriteEngine on
RewriteCond   %{HTTP_HOST}        !^www\.
RewriteRule   ^(.+)               %{HTTP_HOST}          [C]
RewriteRule   ([^.]+)\.tmeet\.com$ fwd.php?username=$1
asgerhallas
Forum Commoner
Posts: 80
Joined: Tue Mar 14, 2006 11:11 am
Location: Århus, Denmark

Post by asgerhallas »

Hmm... I have not tested it, but something like this maybe:

Code: Select all

RewriteEngine on 
RewriteCond   %{HTTP_HOST}        !^www\. 
RewriteCond   %{HTTP_HOST}        !^tmeet\.com
RewriteRule   ^(.+)               %{HTTP_HOST}          [C] 
RewriteRule   ([^.]+)\.tmeet\.com$ fwd.php?username=$1

EDIT:

If your host does not normally allow accessing by "tmeet.com" without subdomain preceeding this might be better:

Code: Select all

RewriteEngine on 
RewriteCond   %{HTTP_HOST} ^tmeet\.com
RewriteRule ^.*$ http://www.tmeet.com [R]

RewriteCond   %{HTTP_HOST}        !^www\. 
RewriteRule   ^(.+)               %{HTTP_HOST}          [C] 
RewriteRule   ([^.]+)\.tmeet\.com$ fwd.php?username=$1
User avatar
evilmonkey
Forum Regular
Posts: 823
Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada

Post by evilmonkey »

asgerhallas wrote:Hmm... I have not tested it, but something like this maybe:

Code: Select all

RewriteEngine on 
RewriteCond   %{HTTP_HOST}        !^www\. 
RewriteCond   %{HTTP_HOST}        !^tmeet\.com
RewriteRule   ^(.+)               %{HTTP_HOST}          [C] 
RewriteRule   ([^.]+)\.tmeet\.com$ fwd.php?username=$1
That did it, thank you very much. :)
Post Reply