The One with the Thoughts of Frans

Archive for July, 2010

Dealing With cPanel: Setting Up a 301 Redirect to Your Main Domain And Preventing .htaccess Hell

cPanel is surprisingly ill-suited for managing domains. Rather than treating each domain as a separate entity, you get one main domain and various so-called add-on domains. The most annoying aspect of this is that it always creates a subdomain when you add a new add-on domain. There should be no such thing as an add-on domain, just a bunch of domains. cPanel has some features that help you work around these defects, but I wasn’t too thrilled with those. It now seems to automatically redirect the www-subdomain to your no-www domain and you can easily set up subdomains to redirect through the interface, but it doesn’t satisfy me.

Setting Up a 301 Redirect

Instead of having to bother with a plethora of settings in cPanel itself, I came up with the following to stick at the top of .htaccess. A quick look around on the Internet brought up Fayaz Miraz’s blog, but while the solution suggestion was close, it misses one crucial aspect: it only redirects from the main page as far as I can tell. This is fixed easily by the addition of $1 (i.e. everything that was added after the main page).

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{HTTP_HOST} !^fransdejonge\.com$
RewriteRule ^(.*)$ //fransdejonge.com/$1 [R=301,L]

</IfModule>

Simply put, it matches all possible routes of approach (whether through www or through a subdomain of another domain) and if it’s not fransdejonge.com, it will 301 redirect to fransdejonge.com. The L means no further rewriting will occur after that rule. Mostly because it would just be inefficient, and partially because something else further down the line might mess things up.

Preventing .htaccess Hell

Another problem is that cPanel automatically creates a /public_html/addondomain directory. This is bad, because /public_html already contains a .htaccess file for the main domain. When accessing /public_html/addondomain, it would first parse the .htaccess file in /public_html before moving on and overriding it in /public_html/addondomain, and that’s assuming none of the rules in /public_html make anything go awry!

To prevent this kind of nightmare from occurring I took the simple precaution of creating a new directory /domains. This domain is contained in /domains/fransdejonge.com, for instance, and any other add-on or subdomains can reside in their own /domains/domain.com directory to prevent any added load from needlessly parsing .htaccess files.

Comments (1)

New URI

After nearly five years of being hosted at a subdomain of Lowter, this blog is now hosted on my own server. I would like to extend my gratitude to Ethan for hosting me all those years.

Comments

Feminism and Atheism

It’s amazing how often I see the same information posted on both the feminist and atheist blogs I follow. Religion is not good to women.

On a very related note, I would highly recommend anyone to read Infidel, the autobiography of Ayaan Hirsi Ali. These issues all come down to treating people equally and fairly regardless of sexuality, gender, race, religion or any other reason, but religion is often in direct opposition with those values. For illustration I’ll quote the devil of whom I just spoke:

Feminists need to be wary of the celebration of “cultural diversity” unless they want to inadvertently celebrate polygamy, child-marriage, marital rape, honor killings, wife beating, selective abortion of female fetuses and other traditions that are now legitimized in the name of culture.

To end this quick post I’ll link to some of my favorite atheist blogs.

  • Pharyngula, no doubt well-known to many. The amount of time he spends debunking quacks is to be admired – or to be pitied. Regardless, his blog is intelligent and provocative and an excellent source of rationality.
  • Friendly Atheist isn’t as entertaining as Pharyngula, but heck, not everything can be.
  • Heaving Dead Cats also hails from the US and telltales of living in a society that sounds like the 1950s to my Dutch ears.

I’ll end this post with Bill & Ted’s idiom, aka the Golden Rule: be excellent to each other.

Comments