.htaccess Archives

Fixing mod_rewrite and .htaccess on GoDaddy Hosting

Published by David Walsh on Thursday, November 5, 200911 Comments

I recently launched a new website on GoDaddy shared hosting. The website required mod_rewrite for SEO-friendly URLs. GoDaddy provides mod_rewrite but every time I tried to hit a two-deep URL, I would get a 404 error. Here’s what I had:

# Mod Rewrite
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

The fix to this problem was to add the following directive before my mod_rewrite directives:

#Fix Rewrite
Options -Multiviews

Tada! The URLs began working and the website’s SEO has taken off!

Adding the XPI MIME Type for Firefox Extension Installs

Published by David Walsh on Tuesday, May 12, 20095 Comments

Yesterday I posted version 0.1 of the David Walsh Blog Toolbar for Firefox. Unfortunately that led to an awkward conversation with my .htaccess file.

.htaccess: I have no idea what to do with this.
me: I want the toolbar to install when they request this file.
.htaccess: Well, how am I supposed to do that?
me: OMG! You don’t know?!
.htaccess: No, just like you didn’t know how to create a Firefox extension before you did the research.
me: Good point. When can you research and start serving it up?
.htaccess: I can’t research. I’m a file.
me: Oh. So I just need to figure things out for you again?
.htaccess: You never pay attention to me anymore…

That went on for quite a while but the moral of the story is that if you want your server to handle XPI files correctly, you need to add the following to your .htaccess file:

Improve Your YSlow Grade Using .htaccess

Published by David Walsh on Tuesday, April 14, 200932 Comments

This post was authored by Eric Wendelin. To learn more about Eric, click here.

A significant part of your YSlow grade depends on how well your site utilizes optimal caching techniques. By editing your .htaccess file, you can increase your YSlow score by 20 points or so in just 3 minutes!

Quick Intro to Caching

Caching is a browser feature that allows storage of certain types of web files on the client-side. In most cases, we want to have our clients cache our static files like HTML and CSS so that our website is faster after the first request.

Quickly Set Up a Templating System Using .htaccess

Published by David Walsh on Monday, November 17, 200819 Comments

Setting up a website capable of easy template switching probably sounds difficult. When I first thought about building a templating system, it felt like a pretty daunting task. After tinkering around for a few days, I found a way that would allow me to switch templates by simply changing a .htaccess directive.

The Folder Structure

+ root
	+ templates
		+ version1
			- css
			- graphics
			- js
		+ version2
			- css
			- graphics
			- js
		+ version3
			- css
			- graphics
			- js

Note that the different templates go in different folders within the temlpates folder — that includes template graphics, CSS styles, and JavaScript files. If any other types of files are specific to your template, you may add a directive to make them template-specific as well.

Check For Module Presence in .htaccess

Published by David Walsh on Friday, November 7, 20085 Comments

One of my favorite Apache modules is mod_rewrite. mod_rewrite allows me to manipulate page URLs so that I can search engine friendly URLs. Not every Apache server has the mod_rewrite module installed so you will want to add a conditional statement within your .htaccess file to make sure it’s there.

The .htaccess

#WordPress's .htaccess code
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

If the “mod_rewrite.c” module is present, that means that mod_rewrite is available and will be used. If not, the mod_rewrite code will be ignored. Using this conditional statement will prevent 500 Internal Server Errors.





© David Walsh 2007-2010. Contact David Walsh. Powered by the remarkable MooTools JavaScript framework.