views:

27

answers:

1

I have a fairly massive web site for which I need to modify the names of the files shown in the URL. I am using Apache 2 with mod_rewrite enabled. I currently have the following configuration in my .htaccess file:

RewriteEngine on
RewriteBase /
RewriteRule ^CakeList\.php$ TastyThingsList.php [T=application/x-httpd-php]

Now, when I access the http://mysitename/CakeList.php I do indeed see the data for the TastyThingsList.php page. If a user types in http://mysitename/TastyThingsList.php, they do see the page, but rather than the address bar reading "TastyThingsList.php" I want it to read "CakeList.php". Is this possible to accomplish using mod_rewrite? Note that the CakeList.php page does not actually exist, I am more or less using it as an alias for the TastyThingsList.php page. I have been reading many of the online tutorials for mod_rewrite, but I cannot seem to find the answer.

In short, whether the user types: http://mysitename/CakeList.php or http://mysitename/TastyThingsList.php, I would like the address in the browser to show http://mysitename/CakeList.php.

Thank you WebCow

+1  A: 

Use the redirect flag for RewriteRule:

RewriteRule ^TastyThingsList\.php$ CakeList.php [R=permanent,L]

This works by returning a URL to the client browser, which actually has to re-request it, and that's how it displays in the address bar to the user.

Ideally, this URL would never be given out if it is never to be used, and might even be configured to be inaccessible if typed in directly.

Unless you have a really weird httpd configuration, you shouldn't need the T flag in the RewriteRule in the question.

Roger Pate