【问题标题】:convert web.config rewrite rule to htaccess rewrite rule (All files without an extension to be processed as .cfm)将 web.config 重写规则转换为 htaccess 重写规则(所有没有扩展名的文件都被处理为 .cfm)
【发布时间】:2017-04-12 16:11:34
【问题描述】:

我正在将一个站点从 IIS 7 移动到 Apache 2.4 并且有以下 web.config 重写规则我在转换为 .htaccess 时遇到了问题。该规则本质上允许通过使用 .cfm 扩展名重写所有没有扩展名的文件(例如 www.mydomain/bag 在服务器上重写为 www.mydomain.com/bag.cfm。在 web 中的工作规则.config 如下所示

<rule name="Rewrite all non extension requests to .cfm" stopProcessing="true">
      <match url="^(.*)$" />
      <conditions logicalGrouping="MatchAll">
        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
        <add input="{REQUEST_FILENAME}.cfm" matchType="IsFile" ignoreCase="false" />
      </conditions>
      <action type="Rewrite" url="{R:1}.cfm" />
    </rule>

我已经尝试了所有可以在这里找到的类似帖子,但不幸的是,它们都不适合我。如果这很重要,我会在 CentOS 7 (Apache 2.4) 上运行 Lucee 5.0。任何指导将不胜感激。

【问题讨论】:

  • 您应该能够自定义此答案以使用 .cfm 而不是 .html:stackoverflow.com/questions/5745490/…
  • 谢谢,是的,我以前试过没有运气。我认为这可能与在 Apache 之后通过 tomcat 代理的“.cfm”文件有关。当我使用您建议的链接时,我似乎接近了,因为当我打开日志记录时,我看到以下内容。 strip per-dir prefix: /home/domain/public_html/bag.cfm -&gt; bag.cfm applying pattern '^(.*)$' to uri 'bag.cfm' pass through /home/domain/public_html/bag.cfm Negotiation: discovered file(s) matching request: /home/domain/public_html/bag (None could be negotiated).
  • 到达 htaccess 时,从非 .cfm 重写为 .cfm 为时已晚。
  • 那么重写需要在哪里?

标签: apache .htaccess mod-rewrite coldfusion lucee


【解决方案1】:

我不太了解 Tomcat;我假设您需要 Apache,因为 Tomcat 不适合提供您的非脚本内容。

您可以将它们设置为具有相同的文档根目录,从而具有一致的 URL,但让 Tomcat 侦听不同的端口,并且不让该端口在外部打开。然后您可以代理针对(隐藏)cfm 文件的请求,如下所示:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME}.cfm -f
RewriteCond %{THE_REQUEST} ^\S++\s++([^?\s]++)(\?\S*)?
RewriteRule ^ http://127.0.0.1:8080%1.cfm%2 [NS,NE,P]
RewriteRule (?<=.cfm)$ http://127.0.0.1:8080/404.cfm [NS,NE,P]

第二条规则是直接请求时假装cfm文件不存在的示例。

您需要启用适当的代理模块。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-08-27
    • 1970-01-01
    • 1970-01-01
    • 2012-08-22
    • 2014-06-30
    • 2016-08-09
    • 1970-01-01
    • 2013-03-12
    相关资源
    最近更新 更多