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).
我目前正在使用ColdFusion开发一个站点,并且有一个mod_rewrite规则,使它看起来像网站使用PHP。对index.php的任何请求都由index.cfm处理(规则将* .php映射到* .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.
这很好 - 到目前为止,非常好。问题是,如果直接请求index.cfm(或任何ColdFusion页面),我想返回404状态代码。
If I try to block access to *.cfm files using mod_rewrite it also returns a 404 for requests to *.php.
如果我尝试使用mod_rewrite阻止访问* .cfm文件,它还会向* .php返回404请求。
I figure I might have to change my Apache config rather than use .htaccess
我想我可能不得不改变我的Apache配置而不是使用.htaccess
3 个解决方案
#1
1
You can use the S
flag to skip the 404
rule, like this:
您可以使用S标志跳过404规则,如下所示:
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.
如果您还使用Alias选项,则还应添加PT标志。有关详细信息,请参阅mod_rewrite文档。
#2
0
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.
我建议在将.php映射到.cfm文件的规则上测试[L]作为首先尝试的东西。
#3
0
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.
您必须使用两组不同的重写规则,一组用于.php,另一组用于.chm,并使它们与RewriteCond%{REQUEST_FILENAME}互斥。并使用jj33建议的标志[L]。
You can keep your rules in .htaccess.
您可以将规则保存在.htaccess中。
#1
1
You can use the S
flag to skip the 404
rule, like this:
您可以使用S标志跳过404规则,如下所示:
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.
如果您还使用Alias选项,则还应添加PT标志。有关详细信息,请参阅mod_rewrite文档。
#2
0
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.
我建议在将.php映射到.cfm文件的规则上测试[L]作为首先尝试的东西。
#3
0
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.
您必须使用两组不同的重写规则,一组用于.php,另一组用于.chm,并使它们与RewriteCond%{REQUEST_FILENAME}互斥。并使用jj33建议的标志[L]。
You can keep your rules in .htaccess.
您可以将规则保存在.htaccess中。