www.domain.com to domain.com

Discuss practical ways rearrange URLs using mod_rewrite.

www.domain.com to domain.com

Postby Guest » Mon Mar 03, 2003 12:24 pm

Hey guys,

Is there a way to rewrite www.domain.com to just domain.com? I have users that use both, and because of that authentication cookies are set wrong, and SSL certificates are getting screwed up. How can I send people to just "domain.com" even if they type in "www.domain.com"? Your help would be greatly appreciated!!
Guest
 

vice vers

Postby Guest, too » Tue Mar 04, 2003 11:41 am

Hi, i want the exact oposite.

my vhost has several serveralias like:

---
ServerName www.domain.com
ServerAlias domain.com *.domain.com domain.net *.domain.net
---

Now i want to rewrite all possibilities to www.domain.com
All rewrite rules i tried seam to work after the first slash - only

i couldnt figure out how to do it ...

-chris
Guest, too
 

Postby zed » Thu Jun 05, 2003 9:03 pm

This more or less describes my problem too.
zed
 

Postby Minifuzzi » Thu Aug 07, 2003 1:15 pm

as mod_rewrite fakes the url the browser will still think hes on domain.com instead of www.domain.com so this wont be of any use for you guys.
i would rather do it with a script. you could include a header that redirects the users if the HTTP_HOST is domain.com. if there's no possiblity to include that into all your scripts i would "redirect" every requests for domain.com to a script that then redirects the users browser to www.domain.com.
i hope you understand what im trying to say :P
Minifuzzi
 

domain.com to www.domain.com

Postby Guest » Tue Aug 12, 2003 9:59 am

One way to do this is....

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.yourdomain\.com
RewriteRule ^(.*)$ http://www.yourdomain.com$1 [R=301,L]

This will send an external redirect to the browser along with a 301 status message which basically states the page has been "permanently moved.

Alan
Guest
 

Postby Guest » Mon Feb 23, 2004 5:44 pm

But then won't subdomains be affected? Like, I cannot have a subdomain.domain.com anymore as everything not www.domain.com will go to www.domain.com...
Guest
 

Postby Guest » Tue Apr 20, 2004 12:15 pm

Yes, subdomains will be affected this way.
And beside that there is a missing slash in the RewriteRule. Try this one instead:

RewriteCond %{HTTP_HOST} ^yourdomain\.com$
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [R=301,L]
Guest
 

Re: domain.com to www.domain.com

Postby http://www-free.info » Mon Sep 20, 2004 9:39 pm

Anonymous wrote:One way to do this is....

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.yourdomain\.com
RewriteRule ^(.*)$ http://www.yourdomain.com$1 [R=301,L]

This will send an external redirect to the browser along with a 301 status message which basically states the page has been "permanently moved.

Alan


is there a way to pick the use %{HTTP_HOST} in rewriterule? Becaues I am using tens of domains and I can not interset them all.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.yourdomain\.com
# turn %{HTTP_HOST} from www.something.com to something.com then
RewriteRule ^(.*)$ %{HTTP_HOST}/$1 [R=301,L]

http://www-free.info
http://www-free.info
 


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 16 guests

cron