The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Other mod_rewrite fun Re: mod_rewrite fun


Sorry for the delay, I thought I would have received an email from your response..

Usually, most of the sites I do run off of just the index file and I use mod rewrite to dynamically include other files or “content” based on the URL which then I’ll have a controller which handles template calls on the fly etc.

If I’m understanding correctly, does this work for you?

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f

# Note: This will add a .php to the end of the slug value
# example:
# /about-us/test will actually be: /about-us?slug=test.php
RewriteRule ^(.*)$ $1.php
RewriteRule ^/index.php$ - [L]

RewriteRule ^about-us/([^/]+) about-us.php?slug=$1 [NC,L]
RewriteRule ^about-us about-us.php [NC,L]

That works on my side. I created an about-us.php file in my root directory and went to /about-us/test which then created /about-us?slug=test.php

I wasn’t sure if you wanted the .php appended at the end so I added a note to one of the Rules above.