prepending www

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

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

prepending www

Post 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!
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

It would probably be better to use the Apache ServerAlias directive than rewriting.
(#10850)
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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/");
}
?>
User avatar
evilmonkey
Forum Regular
Posts: 823
Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada

Post 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.

:D
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post 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.
(#10850)
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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]
User avatar
evilmonkey
Forum Regular
Posts: 823
Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada

Post 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. :)
User avatar
evilmonkey
Forum Regular
Posts: 823
Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada

Post by evilmonkey »

I'll trey the code everah gave me tommorrow. Thanks guys. :)
Post Reply