【问题标题】:How to rewrite url on apache for specific path parameter如何为特定路径参数重写apache上的url
【发布时间】:2014-10-17 15:40:29
【问题描述】:

我想像这样用 mod_rewrite 重写 URL:

example.com/path/foo/rest_of_path-> example.com/path/rest_of_path (remove foo)
example.com/path/bar/rest_of_path-> example.com/path/rest_of_path (remove bar)
example.com/path/sample/rest_of_path-> no rewriting<br/>
example.com/path/test/rest_of_path-> no rewriting

foo, bar 是动态的 test, sample 是静态的,我有路径列表。

所以我正在考虑这样做(在我的 httpd.conf 中):

RewriteCond ....... #it's here i'm blocking, how write only if $1 in test,sample ? 
RewriteRule  ^path/(.\*)/(.*)$  /path/$2

【问题讨论】:

    标签: apache mod-rewrite url-rewriting


    【解决方案1】:
    # You can add as much RewriteCond as you need to exclude static words
    RewriteCond %{REQUEST_URI} !^/path/sample/.*
    RewriteCond %{REQUEST_URI} !^/path/test/.*
    RewriteRule ^path/(.*)/(.*)  /path/$2
    

    【讨论】:

    • 谢谢,但它错过了 [OR] 标志:RewriteCond %{REQUEST_URI} !^/path/sample/.* [OR] RewriteCond %{REQUEST_URI} !^/path/test/.*
    • 不,您不需要 [OR] 而是 AND(这是隐含的)。您希望仅当路径中没有静态单词样本和静态单词测试时才应用 RewriteRule。还是我误会了你?
    猜你喜欢
    • 1970-01-01
    • 2018-10-05
    • 1970-01-01
    • 2012-02-01
    • 2010-11-10
    • 2016-11-27
    • 1970-01-01
    • 1970-01-01
    • 2020-07-09
    相关资源
    最近更新 更多