I'm having trouble getting my rules just right in the per-directory context of mod_rewrite and hoping someone can help me with this.

I have these URLs
urldotcom/this-page.php

Which I want to translate to
urldotcom/index.php?l=this-page

And these URLs
urldotcom/this-dir/that-page.php

Which I can successfully translate to
urldotcom/index.php?this-dir=that-page

Here are the rules I have developed for this.

RewriteEngine on
#
# These three rules translate /{module}/{item_name}.php to index.php?{module}={item_name}
RewriteRule ^([a-zA-Z]+)/([a-zA-Z]+)\.php$ index.php?$1=$2 [L]
RewriteRule ^([a-zA-Z]+)/([a-zA-Z]+-+[a-zA-Z]+)\.php$ index.php?$1=$2 [L]
RewriteRule ^([a-zA-Z]+)/([a-zA-Z]+-+[a-zA-Z]+-+[a-zA-Z]+)\.php$ index.php?$1=$2 [L]
#
# Add an exclusion to index.php, because per-dir context rewrites execute more than once
RewriteCond %{request_uri} !^index\.php$
#
# Rewrites the listing URLS, whose filename specifies the listing to load
RewriteRule ^(.*).php$ index.php?l=$1 [NC,L]

The first three RewriteRules work in that they do what I want them to. In trying to use the last rule and it's associated condition however, the query string it always passes to the page is
l=index

When l should equal the filename. I think this is happening because mod_rewrite executes more than once when being used in a .htaccess file and so I added the RewriteCond to exclude index.php but it isn't working for me at all.

Can anyone give me a hand with this?

    Write a Reply...