Ad

Mod_rewrite To Alias One File Suffix Type To Another

- 1 answer

I hope I can explain this clearly enough, but if not let me know and I'll try to clarify.

I'm currently developing a site using ColdFusion and have a mod_rewrite rule in place to make it look like the site is using PHP. Any requests for index.php get processed by index.cfm (the rule maps *.php to *.cfm).

This works great - so far, so good. The problem is that I want to return a 404 status code if index.cfm (or any ColdFusion page) is requested directly.

If I try to block access to *.cfm files using mod_rewrite it also returns a 404 for requests to *.php.

I figure I might have to change my Apache config rather than use .htaccess

Ad

Answer

You can use the S flag to skip the 404 rule, like this:

RewriteEngine on

# Do not separate these two rules so long as the first has S=1
RewriteRule (.*)\.php$ $1.cfm [S=1]
RewriteRule \.cfm$ - [R=404]

If you are also using the Alias option then you should also add the PT flag. See the mod_rewrite documentation for details.

Ad
source: stackoverflow.com
Ad