Forum Moderators: phranque

Message Too Old, No Replies

rewriting aliased domain names

         

Mbuna

7:06 pm on Feb 25, 2006 (gmt 0)

10+ Year Member



I have a site that has many domain aliases pointing to it.

Is there a way with mod_rewrite to rewrite any url that doesn't start with www to add the www?

I know this is easy for a single domain, but what I want is to simply tack on the www to whatever aliased domain they used to get to the site.

http://www.example.info
http://www.example.com
http://www.example2.com

tnx,

Sean

[edited by: jdMorgan at 2:45 am (utc) on Feb. 26, 2006]
[edit reason] No URLs or sigs, please, See Terms of Service. [/edit]

extras

9:43 pm on Feb 26, 2006 (gmt 0)

10+ Year Member



Some examples.
[webmasterworld.com...]

You can find most info by searching.
[webmasterworld.com...]

Mbuna

3:16 am on Feb 27, 2006 (gmt 0)

10+ Year Member


Extras,

I didn't see anything that pertained to my question in your examples posts.

To clarify I have one site with many aliases. I want to rewrite what ever domain they come to as www.domain

ex:

http://domain1.com rewrites to http://www.domain1.com
http://domain5.com rewrites to http://www.domain5.com
http://domain7.info rewrites to http://www.domain7.info

I can't rewrite the domain part because the site is dynamic and does database queries based on the http host variable.

I simply want to tack on www to any http host that comes in that doesn't already have the www in it.

Tnx again,

Sean

extras

2:46 pm on Feb 27, 2006 (gmt 0)

10+ Year Member



Please read the link I showed, again (and again).
[webmasterworld.com...]

It shows examples of exactly what you want and explanations.

jdMorgan

3:06 pm on Feb 27, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Mbuna,

Welcome to WebmasterWorld!

Your threads will get a faster response if you post the code you have written and tested first. We cannot write code on demand here, as demand would quickly outstrip the time available to our all-volunteer members and staff. See our forum charter [webmasterworld.com] for more information.


# If requested hostname does not start with "www."
RewriteCond %{HTTP_HOST} !^www\.
# Get hostname into variable %1 (drop port if present)
RewriteCond %{HTTP_HOST} ^([^:]+)
# Prepend "www" to requested hostname
RewriteRule (.*) http://www.%1/$1 [R=301,L]

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim

Mbuna

5:32 pm on Feb 27, 2006 (gmt 0)

10+ Year Member



Thanks Jim,

That was exactly what I was looking for and was well commented so I could understand what it was doing.

Thanks again.

Extra,

I read through that thread again and still couldn't find there this was done. It seemed that this thread was focused on https? And I have to say that much of what you posted I simply didn't understand so it's certainly possible it's there and I just missed it.

Mbuna

5:34 pm on Feb 27, 2006 (gmt 0)

10+ Year Member



Ok, now I found it down in the second to last post.
Tnx

Sean