Mod_rewrite for an alias of one type of file suffix for another

I hope I can explain this clearly enough, but if you do not tell me, I will try to clarify.

I am currently developing a site using ColdFusion and have a mod_rewrite rule to make it look like the site is using PHP. Any requests for index.php are handled by index.cfm (the rule maps * .php to * .cfm).

It 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.

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

I suggest that I may have to change the configuration of Apache and not use .htaccess

+3
source share
3 answers

You can use the flag Sto skip the rule 404, for example:

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 also use the parameter Alias, you must also add a flag PT. See the mod_rewrite documentation for more details .

+1
source

Publish the rules that you already have as a starting point so people can’t recreate them to help you.

I would suggest checking [L] on a rule that displays .php files in .cfm in the first place to try it.

0
source

: .php, .chm RewriteCond% {REQUEST_FILENAME}. [L], jj33.

.htaccess.

0

Source: https://habr.com/ru/post/1696400/


All Articles