Page 1 of 1
prepending www
Posted: Mon May 08, 2006 10:16 am
by evilmonkey
Hello,
I have the following mod_rewrite rules to forward xxxxxx.tmeet.com to
http://www.tmeet.com/fwd.php?user=xxxxxx. I now want to add a rule that would take
http://tmeet.com and make into
http://www.tmeet.com. How can I do that?
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
Thanks!
Posted: Mon May 08, 2006 11:22 am
by RobertGonzalez
I am not certain how to do this, but I ran across
a thread in another forum on this topic.
I'm not much of a mod_rewrite guru, but can you set up a rule for just the tmeet.com url?
Code: Select all
RewriteRule tmeet\.com www.tmeet.com
Just a thought. Have not idea if it can or will work.
Posted: Mon May 08, 2006 12:49 pm
by Christopher
It would probably be better to use the Apache ServerAlias directive than rewriting.
Posted: Mon May 08, 2006 1:17 pm
by RobertGonzalez
Don't know if it will be helpful, but
here are a bunch of examples of mod_rewrite from the guy that developed it.
Is there a way you can do it code-side, say by checking the $_SERVER['HTTP_HOST'] value of the page?
Code: Select all
<?php
if (!strpos($_SERVER['HTTP_HOST'], 'www.'))
{
header("Location: http://www.tmeet.com/");
}
?>
Posted: Mon May 08, 2006 1:43 pm
by evilmonkey
Hmm...okay...putting it into PHP is not a good idea. I'm having no luck. I really want to do this through htaccess. Can someone show me what I can add to the code above to prepend the www? Thanks.

Posted: Mon May 08, 2006 1:52 pm
by Christopher
It needs to go in your web server configuration because the name needs to be resolved before it ever gets to a directory (and a .htaccess file). ServerAlias is the way to do that.
Posted: Mon May 08, 2006 4:27 pm
by RobertGonzalez
OK, so I admit it. I was totally intrigued and stumped by this problem. So I ran across
a forum dedicated to mod_rewrite and
posed this same problem there. This was the response (customized to evilmonkey's website). Don't know if it will work, but I figured it was worth the shot. Not to mention I really want to know how to do it. Not so I can use it, just so I know if it can, and how it might be, done. Anyhow, this may be something to try...
Code: Select all
RewriteEnigne On
RewriteCond %{HTTP_HOST} ^tmeet\.com$ [NC]
RewriteRule .* http://www.tmeet.com%{REQUEST_URI} [QSA,R=301,L]
RewriteCond %{HTTP_HOST} !^(www\.)?tmeet\.com$ [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.tmeet\.com$ [NC]
RewriteRule .* fwd.php?username=%1 [L]
Posted: Mon May 08, 2006 5:25 pm
by evilmonkey
arborint wrote:It needs to go in your web server configuration because the name needs to be resolved before it ever gets to a directory (and a .htaccess file). ServerAlias is the way to do that.
That's already taken care of.

Posted: Mon May 08, 2006 5:35 pm
by evilmonkey
I'll trey the code everah gave me tommorrow. Thanks guys.
