【问题标题】:htaccess: how to redirect every url that starts with http://example.com/shophtaccess:如何重定向以 http://example.com/shop 开头的每个 url
【发布时间】:2010-10-02 08:46:23
【问题描述】:

如标题所说,如何将每个以http://example.com/shop 开头的网址重定向到单个页面?

所以我有:

....等,它应该被重定向到http://example.com/new_page

【问题讨论】:

    标签: .htaccess redirect


    【解决方案1】:

    你可以使用mod_alias’ RedirectMatch:

    RedirectMatch ^/shop(/|$) /new_page
    

    mod_rewrite:

    RewriteEngine on
    RewriteRule ^shop(/|$) /new_page [R]
    

    请注意 RewriteRule 的不同模式,因为 mod_rewrite 在测试规则之前会删除 per-directory rewrites 中的上下文路径前缀。

    【讨论】:

    • 我猜 mod_alias 与 mod_rewrite 不同? [R] 是什么意思?
    • @krike:是的。使用 mod_alias 的指令,您只能处理 URI 路径;使用 mod_rewrite 您还可以测试请求的其他部分,例如查询或标头字段。 [R] 是强制外部重定向;否则请求只会在内部被重写。
    • 好的,谢谢 :) 将在我完成我的网站的新版本后立即尝试 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-08-09
    • 2020-12-24
    • 2012-09-29
    • 2021-04-29
    • 1970-01-01
    • 2017-11-19
    • 1970-01-01
    相关资源
    最近更新 更多