【问题标题】:Is there a way to redirect url with embedded query param有没有办法使用嵌入式查询参数重定向 url
【发布时间】:2015-06-18 15:23:56
【问题描述】:

我正在尝试编写重定向表单网址的重定向规则:

http://example.com/?lang=fr/hub/anypagehere => http://example.com/hub/anypagehere/?lang=fr

仅当 url 中有“hub”时。

有没有办法用 .htaccess 做到这一点?

【问题讨论】:

标签: php .htaccess redirect url-redirection


【解决方案1】:

你可以使用这条规则:

RewriteEngine On

RewriteCond %{QUERY_STRING} ^([a-z]{2})/(hub/.*)$ [NC]
RewriteRule ^/?$ /%2/?lang=%1 [R=301,L]

【讨论】:

    【解决方案2】:

    像这样:

    RewriteEngine On
    RewriteCond %{QUERY_STRING} ^(.*)\/hub\/(.*)$
    RewriteRule ^(.*)$ /hub/%2/?lang=%1 [R=302,L]
    

    【讨论】:

    • 避免在文件中硬编码域等,即使在 .htaccess 中也是如此。
    猜你喜欢
    • 2016-09-20
    • 2011-01-15
    • 2019-05-06
    • 2015-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多