Web Hosting Talk







View Full Version : modrewrite question


hardjoko
05-01-2007, 12:52 AM
Hi,

This is my .htaccess

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
Errordocument 404 /404.html
RewriteCond %{REQUEST_FILENAME} !\.(jpg|jpeg|gif|png|css|js)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php [L]
</IfModule>

Basically, if file exist just call the file
If the is not ended in jpg, jpeg, gif, png, css, or js, and doesn't exist then call index.php

Does that mean it'll call 404.html for all files that ended in jpg, jpeg, etc?

What happened when 404.html doesn't exist?

SparkJim
06-17-2007, 02:13 AM
This is my .htaccess

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
Errordocument 404 /404.html
RewriteCond %{REQUEST_FILENAME} !\.(jpg|jpeg|gif|png|css|js)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php [L]
</IfModule>


With the above rules in .htaccess, redirection to "index.php" happens only 1) the name doesn't end with jpg,jpeg,gif,png,css,js and 2) the requested file doesn't exist

So in short, suppose you have the following files under your docroot,

.htaccess, index.php, button.gif, 404.html and test.html

these links will NEVER get redirected - http://domain.com/anything.jpg, http://domain.com/test.html, http://domain.com/button.gif. But http://domain.com/nonexisting.html file will be redirected to index.php.

For every 404 ( file not found error ), 404.html will be displayed. If 404.html doesnt exist, index,php will be called.

I personally suggest you to set up a test domain on your local machine and play with it.:agree: