.htaccess redirect but mask url

Hi all,

I am somewhat new to configuring htaccess. I will explain what I am trying to do.

I have a bunch of pages say about.php, welcome.php, new.php. These pages don’t actually exist on the server, but rather in the db.

This is how I need it to work. When I type in http://www.domain.com/about.php it essentially loads a template file, which then grabs the about.php from the url and then grabs the content from the database. It then just echos the data in.

I can’t have the url change. Not sure if this is possible or not but any help would be great.



It’s quite possible with Mod_Rewrite. I’m a little rusty, but this should work (adjust file names to suit):

// .htaccess
RewriteEngine On
RewriteRule ^([a-z]+).php$ template.php?content=$1 [L,NC]


Mike’s nearly got it but his code will loop on template.php (and NC is useless in this context):

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/?template\\.php$
RewriteRule ^([a-z]+).php$ template.php?content=$1 [L]

That, of course, starts by ensuring the RewriteEngine is On, checks whether the requested file is template.php then redirects other .php file requests to template with the query string identifying the name of the requested file. Since the redirection is not absolute and not permanent, it’ll remain hidden from view.



Opps :blush:

Wouldn’t NC be helpful in this case? Never know what someone might type in :stuck_out_tongue:


Don’t pet the sweaty stuff! :lol:

NC will cause the regex to match whether UPPERCASE or lowercase which is usually applicable to domain names (%{HTTP_HOST}). As you know, it pays to specify for your regex ([a-z]+ would become [a-zA-Z]+) - or allow mod_speling to FIND the correct capitalization for you!

You’ve been here and seen my “ballistics” :lol: about not specifying the regex properly even though that’s been mostly about the EVERYTHING atom - the :kaioken: (.*) :kaioken: !