mod_rewrite to alias one file suffix type to another

Question :

mod_rewrite to alias one file suffix type to another,

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.

Read More  Strange C++ errors with code that has min()/max() calls

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


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 for details.

Read More  Best way to hide DB connection code in PHP5 for apps that only require one connection?

That’s the answer mod_rewrite to alias one file suffix type to another, Hope this helps those looking for an answer. Then we suggest to do a search for the next question and find the answer only on our site.

Disclaimer :

The answers provided above are only to be used to guide the learning process. The questions above are open-ended questions, meaning that many answers are not fixed as above. I hope this article can be useful, Thank you