Removing www. from your websites

Uncategorized — Tags: — Panayotis @ 09:07

Here is a short tip on how to remove “www.” from your sites (and make sure others do not use it too). You will need mod_php (apache) enabled and PHP.

In the default virtual host base directory, make sure you have enabled mod_rewrite (check your Override directives if the following does not work), and add something like this in .htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule ^(.*) go.php

Then put in the same directory go.php:
< ?
$g = str_replace('www.','',$_SERVER['HTTP_HOST']) ;
header("Location: http://$g". $_SERVER["REQUEST_URI"]) ;
?>

2 Comments »

  1. Check my solution here:
    http://rapidsignal.com/blog/2005/10/24/removing-www/

    This way you don’t need a php file plus redirection keep the full url
    e.g.
    http://www.site.com/path/to/file.php?par=1
    will send you to
    http://site.com/path/to/file.php?par=1

    Comment by Dimitris Giannitsaros — 2006-07-05 @ 09:07
  2. Yes, but I have multiple domains. I could not find a way to use the domain name in the rewrite rule.

    Comment by Panayotis — 2006-07-05 @ 11:07

RSS feed for comments on this post. TrackBack URI

Leave a comment

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.
(c) 2008 vrypan|net|log | powered by WordPress with Barecity