【问题标题】:Redirection with Apache2 query_string with square brackets使用带有方括号的 Apache2 query_string 进行重定向
【发布时间】:2013-05-27 13:24:37
【问题描述】:

我有一个类似

的网址
http://domain.net/documents?f[author]=43

应该重定向到哪个

http://domain.net/documents/author/43

到目前为止我所拥有的是

RewriteEngine On    
Rewritebase /documents
RewriteCond %{query_string} f([^/]+)=(.*)$ [NC]
RewriteRule (.*) author/%2? [R=301,L]

但是,这会重定向所有 URL,包括 http://domain.net/documents/author/43?page=1 回到 http://domain.net/documents/author/43 当我只需要用“/author/”替换“?f[author]=”部分时

【问题讨论】:

    标签: apache mod-rewrite query-string httpd.conf querystringparameter


    【解决方案1】:
    RewriteEngine On    
    Rewritebase /documents
    
    RewriteCond %{ENV:REDIRECT_STATUS} !200
    RewriteCond %{query_string} f([^/]+)=(.*)$ [NC]
    RewriteRule (.*) author/%2? [R=301,L]
    

    【讨论】:

    • 感谢您的回复,但是,我的东西似乎比我之前想象的要复杂一些,看起来我只需要在完整的短语 "?f[author]=" 为在 URL 中,我应该放什么而不是 RewriteCond %{query_string} f([^/]+)=(.*)$ [NC] 如果我想要出现字符串 "?f[author]=" 的页面?跨度>
    • 非常感谢 Gerben,这首先在“?f[author]=”被重定向时有效,但在随后的 URL(单击更多)上,我得到了文档/作者/23054?page= 1 它应该是文档吗?page=1&f[author]=23054 - 我猜需要另一个表达式来将 URL 从文档/作者/FIRST?page=SECOND 重定向到文档?page=SECOND&f[author]=FIRST 你能帮忙?
    • 对不起,我没有关注。可以添加您的整个 htaccess。
    • 到目前为止我有这个: DocumentRoot /home/website/prod RewriteEngine On RewriteEngine On Rewritebase /documents RewriteCond %{ENV:REDIRECT_STATUS} !200 RewriteCond %{query_string} f ([.+])=(.*)$ [NC] RewriteRule (.*) 作者/%2? [R=301,L] 它按预期将domain.net/documents?f[author]=43 重定向到domain.net/documents/author/43 现在,我需要将domain.net/documents/author/43?page=1 重定向到domain.net/documents?page=1&f[author]=43
    • 但是domain.net/documents/author/43 是如何处理的呢? /documents/author 中是否真的有一个名为 43 的文件?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-05
    • 2012-03-07
    • 1970-01-01
    • 1970-01-01
    • 2020-12-30
    • 1970-01-01
    相关资源
    最近更新 更多