views:

31

answers:

2

Hi all apache experts,

I have a problem adding a default rewrite php and html requests to my apache .htaccess.

The idea is to set up templates for the content on my site, specifying that the content in a folder uses a specific template. It works fine for html, image and other resources; requests are rewritten to the template nicely. But I get a recursive problem rewriting request to php-resources, because the template is also a php-resource… perhaps logically enough.

Is it possible to limit the php-to-php to a single rewrite? Or do I need another approach ?

This rule is my problem:

RewriteRule ^(.*).(php$) /_templates/default.php?$1.$2 [NC,L]

Below is my .htaccess...

Thanks...

# Template rewrites:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(subpages/.*) /_templates/present.php?$1 [NC,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*).html$ /_templates/default.php?$1 [NC,L]
RewriteRule ^(.*).(php$) /_templates/default.php?$1.$2 [NC,L]
A: 

You can add a RewriteCond like this:

RewriteCond $1 !^_templates/
RewriteRule ^(.*).php$ /_templates/default.php?$1.php [NC,L,B]

I also added the B flag because you're using the backreference in the query string.

Artefacto
Thanks Artefacto,the RewriteCond $1 !^_templates/ may the trick... Cheers
Alfa Stone
A: 

You can add an exclusion rule :

RewriteRule /_templates/default.php(.*)$ $0 [L]

$0 is the original request and [L] means it is the last rule this request will run

Gareth Midwood
Thanks Gareth...
Alfa Stone