Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am trying to drop extensions and enable access such that requests for "/", "/index", and "/index.ext" all return the same resource.

At the same time, I want every such resource to go through a PHP script that includes a header, footer, and does other processing before sending it back to the client as the resource they requested.

How do I do this using only .htaccess? Even with MultiViews off, I've hit a brick wall where every attempt results in an infinite rewrite loop.

share|improve this question
add comment

2 Answers 2

Exclude static files (.js, .css etc):

RewriteEngine on
RewriteRule !\.(js|ico|gif|jpg|png|css)$ /index.php

Exclude the same static files but allow real files and directories:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule !\.(js|ico|gif|jpg|png|css)$ /index.php

As recommended by the Zend Framework.

share|improve this answer
    
+1 !\.(js|ico|gif|jpg|png|css)$ - Good call, makes sense to skip PHP if the resource type isn't supported –  danlefree Oct 1 '10 at 16:00
    
The first one results in another infinite rewrite loop and produces a 500 error. The second one works but it doesn't allow me to do any processing outside of the requested file. Basically I need a way to pass the value of the page to the handler script so that it can be included between includes of the header and footer. –  Hugh Guiney Oct 3 '10 at 12:23
add comment
RewriteEngine on

# Route all requests on non-existent directories and files to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /index.php [L,QSA]

You might also check out AskApache's excellent HowTo's for more mod_rewrite recipes.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.