Card store project #5: Redirecting my www-prefixed domain to my non-www-prefixed domain
For search engine optimization and analytics, I wanted to make
http://www.handsoncards.com/
permanently redirect to http://handsoncards.com/.
So I started Googling. It took me a while to figure this one out... The first few articles I read
suggested using Rewrite directives in my .htaccess file but this didn't work for me
(maybe because I'm using mod_python and Django?). Then I found I could use
Rewrite in my httpd.conf file, but I got an infinite redirect loop.
Finally, I found the solution from
this discussion. Here's what I did. I'm using Django, mod_python, and
Apache on Ubuntu at Slicehost.
- Enable mod_rewrite. Logged in as root:
a2enmod rewrite
- Edit
/etc/apache2/httpd.conf:<VirtualHost *> ServerName handsoncards.com ServerAlias www.handsoncards.com # RewriteEngine on RewriteCond %{HTTP_HOST} ^www\.handsoncards\.com RewriteRule (.*) http://handsoncards.com$1 [R=301,L] # SetHandler python-program PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE handsoncards.settings PythonPath "['/srv/HandsOnCards', '/srv/python-packages'] + sys.path" PythonDebug Off </VirtualHost> - Restart Apache:
/etc/init.d/apache2 restart
Post a comment
About
I'm Eliot and this is my notepad for programming topics such as Python, Django, Ubuntu, Emacs, etc... more »
Search Blog
Tags
-
algorithms
(4)
-
aws
(8)
-
blogproject
(20)
-
c_cplusplus
(12)
-
cardstore
(8)
-
colinux
(2)
-
concurrency
(9)
-
conkeror
(2)
-
cygwin
(18)
-
datastructures
(15)
-
datetime
(3)
-
dell
(3)
-
django
(39)
-
emacs
(20)
-
files_directories
(10)
-
install_setup
(7)
-
javascript
(3)
-
keyboard
(6)
-
matplotlib
(5)
-
mercurial
(4)
-
nginx
(2)
-
preferences
(8)
-
processes
(3)
-
pyqt
(18)
-
python
(122)
-
ratpoison
(3)
-
regexes
(5)
-
rsync
(3)
-
softwaretools
(17)
-
sql
(13)
-
ssh
(7)
-
subversion
(6)
-
twisted
(6)
-
ubuntu
(60)
-
urxvt
(5)
-
vxworks
(25)
-
webservices
(4)
-
wmii
(7)
Blogroll
- Adam Gomaa
- Alex Clemesha
- Amir Salihefendic
- Armin Ronacher
- David Beazley
- David Ziegler
- Duncan McGreggor
- Gareth Rushgrave
- Glyph Lefkowitz
- Guido van Rossum
- Ian Bicking
- Jacob Kaplan-Moss
- James Bennett
- James Tauber
- Jesper Noehr
- Matt Harrison
- Nikolay Kolev
- Parand Darugar
- Peter Baumgartner
- Peter Bengtsson
- Rob Hudson
- Simon Willison
- Will McGugan