Jason Leveille’s Blog

Beauty’s where you find it

Archive for the ‘htaccess’ Category

Remove www Subdomain

It seems that more and more people are moving away from the inclusion of www in their url. SitePoint recently wrote about the subject, and this past February Roger Johansson also wrote an article on the topic. Roger’s article was really more about making sure your site works with our without www (I couldn’t agree more). You wouldn’t get any more from me than you could get from taking a look at the articles I’ve referenced, therefore I’ll just skip to the good stuff. In general I feel that the inclusion of www is just a waste of address bar space. For this blog I have decided to throw it to the dogs. If I remember correctly, “Removing the Ws from URLs“, an article from 2002, was a big help for me on my path to www enlightenment.

Removing WWW through VirtualHost

<VirtualHost ipaddress>
ServerAdmin root@localhost
ServerAdmin webmaster@blueatlas.com
DocumentRoot /path/to/public_html/
ServerName jasonleveille.com
ErrorLog /path/to/logs/jasonleveille.com/error_log
TransferLog /path/to/logs/jasonleveille.com/access_log
</VirtualHost>

<VirtualHost ipaddress>
ServerName jasonleveille.com
ServerAlias www.jasonleveille.com
ServerAlias ww.jasonleveille.com
Redirect permanent / http://jasonleveille.com/
</VirtualHost>

Removing WWW through .htaccess

Perhaps you don’t have access to your VirtualHost block. Not a problem if your host/server/whatever allows you to override directives via .htaccess. This article on using .htaccess from Daring Fireball is a good reference regarding this topic.

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.yourdomain\.com$
RewriteRule (.*) http://yourdomain.com/$1 [R=Permanent]
  • 1 Comment
  • Filed under: Apache, htaccess
  • Permanent Redirects and CakePHP

    I recently had the need to set up some permanent redirects for an application built on CakePHP. My first thought was to use a simple .htaccess Redirect at the top of my www .htaccess file, like such:

    Redirect 301 /foo /bar

    However, the result of the redirect was actually the following url:

    http://foobar.com/bar?url=foo

    This has to do with the QSA flag in the last RewriteRule of the root htaccess file. The QSA flag indicates that a query string should be appended to the url. In our case, foo is recognized as the query string and it ultimately is appended at the end of the bar redirect. Not what I wanted, as the appending of foo to bar results in a 404 error. (more…)

  • 0 Comments
  • Filed under: CakePHP, htaccess