[thelist] removing the www. from my urls

Joe Crawford joe at artlung.com
Fri Mar 19 15:30:05 CST 2004

On Fri, 19 Mar 2004, Dunstan Orchard wrote:
> Does anyone know of any .htaccess code I can use to remove the www. from
> my urls?
> I did try this:
> # remove the www from url
> RewriteCond %{HTTP_HOST} ^www\.1976design\.com$ [NC]
> RewriteRule ^(.*)$ http://1976design.com/$1 [R=301,L]
> from the guys at:
> http://no-www.org/
> And while it worked for my homepage, it failed to rewrite anything
> beyond that. So if someone came directly to:
> http://www.1976design.com/blog/

I use this (in PHP):
if($SERVER_NAME!='server.dom') {
        header("Location: http://server.dom" . $REQUEST_URI);

In ColdFusion (untested code!!):
<cfif CGI.SERVER_NAME is not "server.dom">
<cflocation url="http://server.dom#CGI.REQUEST_URI#" addtoken="no">

In ASP (untested code!!):
if Request.ServerVariables("SERVER_NAME") <> "server.dom" then
Response.Redirect("http://server.dom" &  _
end If

Put whatever's appropiate in an include at the tippy-tops of all your
pages and that should work.

Joe "ArtLung" Crawford   AIM:artlung   Phone:619-516-4550
LAMP Host Evangelist, Web Designer, Web Developer, WebSanDiego.org List Guy
http://joecrawford.com/  http://lamphost.net/  http://artlung.com/
http://artlung.com/blog/  http://sandiegobloggers.com/
http://sandiegoblog.com/  http://websandiego.org/

More information about the thelist mailing list