【问题标题】:Setting the HTACCESS file to redirect all .cfm requests to index.php设置 HTACCESS 文件以将所有 .cfm 请求重定向到 index.php
【发布时间】:2015-07-13 17:22:43
【问题描述】:

我写了一个 .htaccess 重写规则,它应该接受容器 index.cfm 的任何请求并将它们重定向到 index.php。

http://testsite.com/index.cfm/a/catalog.prodShow/vid/42110/catid/154

但是,它没有正确重定向。如果我只是输入 index.cfm(没有其余的 url)它可以正常工作,但是,当 /a/... 添加到它时,它会将我带到 404 页面。

如何调整我的规则,使其适用于任何包含 index.cfm 的网址?

这是我的规则:

重写规则 ^index.cfm$ /index.php [L,NC,R]

谢谢。

【问题讨论】:

    标签: apache .htaccess mod-rewrite redirect


    【解决方案1】:

    在您的 RewriteRule 中,^$ 表示行的开始和结束。如果您希望匹配任何 index.cfm(如 /index.cfm/a/.../sub1/sub2/index.cfm/...),您可以尝试:

    RewriteRule ^(.*index.cfm.*)$ /index.php?original_url=$1 [L,NC]
    

    我添加了原始 url 作为参数,因为您可能需要它来处理请求,并且我删除了 R 标志以避免循环。

    【讨论】:

    • 我逐字尝试过,但似乎没有用。我把R放回去了,它成功了!谢谢。
    猜你喜欢
    • 2016-11-30
    • 2015-04-10
    • 2012-12-07
    • 1970-01-01
    • 2016-04-15
    • 1970-01-01
    • 2012-11-16
    • 2013-10-26
    • 1970-01-01
    相关资源
    最近更新 更多