views:

614

answers:

3

Hi guys,

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, but any help is greatly appreciated.

Thanks, James

A: 

Post the rules you already have as a starting point so people don't have to recreate it to help you.

I would suggest testing [L] on the rule that maps .php to .cfm files as the first thing to try.

jj33
A: 

You have to use two distinct groups of rewrite rules, one for .php, the other for .chm and make them mutually exclusives with RewriteCond %{REQUEST_FILENAME}. And make use of the flag [L] as suggested by jj33.

You can keep your rules in .htaccess.

PW
+1  A: 

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.

Ted Percival