.htaccess Archives
Published by David Walsh on Thursday, November 5, 2009 •
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!
Published by David Walsh on Tuesday, May 12, 2009 •
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:
Published by David Walsh on Tuesday, April 14, 2009 •
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.
Published by David Walsh on Monday, November 17, 2008 •
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.
Published by David Walsh on Friday, November 7, 2008 •
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.