【问题标题】:How to redirect folder without affecting its files in apache?如何重定向文件夹而不影响其在apache中的文件?
【发布时间】:2015-03-15 04:21:33
【问题描述】:

我的.htaccess 文件中有以下重写规则:

Redirect 301 /products http://example.com/products.html

这很好用,但是它会影响文件夹内文件的 URL,所以:

http://example.com/products/item.html

被重定向到:

http://example.com/products.html/item.html

有什么方法可以让我的重定向只针对父文件夹而不是其中的文件?

【问题讨论】:

    标签: apache .htaccess redirect http-status-code-301


    【解决方案1】:

    有什么方法可以让我的重定向只针对父文件夹而不是其中的文件?

    是的,使用RedirectMatch 使用正则表达式进行精确定位:

    RedirectMatch 301 ^/products/?$ http://example.com/products.html
    

    正则表达式 ^/products/?$ 将匹配 /product/product/ 但不匹配 /product/file

    【讨论】:

    • 谢谢我在玩 RedirectMatch 但我无法正确使用正则表达式
    猜你喜欢
    • 1970-01-01
    • 2011-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-07
    • 2015-05-09
    • 2017-06-09
    • 2022-01-09
    相关资源
    最近更新 更多