Wednesday, November 12, 2008

Godaddy URL Rewriting for PHP

I'm hosting some new projects at Godaddy on their "Deluxe Hosting - Linux" plan.

I want my external URLs to end in .html, but I'm coding the site in php5.
The web is full of example .htaccess directives that don't work.

Here's all you need:
Create a file called ".htaccess" in the root folder for your domain.
Put the following in that file:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule (.*).html $1.php [L]


Now when someone requests index.html, the server will execute index.php.
Cake.

If you want to keep some html files, use the following:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteRule (.*).html $1.php [L]


The "RewriteCond" tests to see if the html file exists. If it does, then it is served normally. If it does not, then the php version of that name is served up.

DISCLAIMER:
I know this super-simple url_rewrite example diminishes my nerd cred. (People are more used to seeing external maps or mod_perl magic from me.) But I figured there's plenty of non-techies out there who will find this basic information valuable.




Technorati Tags: , , , , , ,

No comments:

Post a Comment

Please leave your comment here.