【问题标题】:Mod-Rewrite: only in specific directory and before the other directoriesMod-Rewrite:仅在特定目录和其他目录之前
【发布时间】:2014-07-30 08:11:25
【问题描述】:

更具体一点: 我想要一个看起来像的链接

domain.com/onlyinthisdir/en/something/ OR
domain.com/onlyinthisdir/en/something/some/thing/

但是Mod rewrite可以做到

domain.com/onlyinthisdir/something/?lang=en
domain.com/onlyinthisdir/something/some/thing/?lang=en

没有用户重定向,但它只发生在内部。

我的第一次尝试就是这样。但它只适用于“onlyinthisdir”目录,而不适用于下面的其他目录

RewriteRule ^onlyinthisdir/([^/]*)/$ /onlyinthisdir/?lang=$1 [L]

我什至不确定这是否真的有效。是否有更好的选择来检测语言?

【问题讨论】:

    标签: regex apache .htaccess mod-rewrite query-string


    【解决方案1】:

    你可以使用这条规则:

    RewriteCond %{QUERY_STRING} !(^|&)lang=[^&]+ [NC]
    RewriteRule ^onlyinthisdir/([a-z]{2})/(.*)$ /onlyinthisdir/$2?lang=$1 [L,QSA]
    

    【讨论】:

    • 太棒了!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-21
    • 2012-03-23
    • 2011-12-16
    相关资源
    最近更新 更多