开发者

.htaccess and page names

开发者 https://www.devze.com 2022-12-15 03:52 出处:网络
I have a fairly massive web site for which I need to modify the names of the files shown in the U开发者_Python百科RL.I am using Apache 2 with mod_rewrite enabled.I currently have the following configu

I have a fairly massive web site for which I need to modify the names of the files shown in the U开发者_Python百科RL. 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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消