【问题标题】:Remove characters from query string从查询字符串中删除字符
【发布时间】:2015-11-28 22:51:06
【问题描述】:

我需要重定向

http://example.com/page/?Id=1253-23098-

到

http://example.com/page/1253-23098

此重定向还包括从查询字符串末尾删除“-”。

我所做的是

RewriteEngine On
RewriteCond %{REQUEST_URI}  ^/page/$
RewriteCond %{QUERY_STRING} ^Id=([0-9\-\0-9]*)$
RewriteRule ^(.*)$ http://example.com/page/%1? [L,R=301]

将我重定向到

http://example.com/page/1253-23098-

我需要从我的查询字符串中删除“1253-23098”之后的任何内容。

我在过去 3-4 小时内搜索了它,但似乎没有任何效果。 任何帮助表示赞赏。

【问题讨论】:

    标签: .htaccess redirect url-rewriting query-string url-redirection


    【解决方案1】:

    试试:

    RewriteEngine On
    RewriteCond %{REQUEST_URI}  ^/page/?$
    RewriteCond %{QUERY_STRING} ^Id=([0-9]*)-([0-9]*)-$ 
    RewriteRule ^(.*)$ http://example.com/page/%1-%2? [L,R=301]
    

    【讨论】:

    • 您的回答也是正确的,只是它在 1253-23098 之后不处理查询字符串“除了'-',感谢您的努力
    【解决方案2】:

    你可以使用:

    RewriteEngine On
    RewriteCond %{QUERY_STRING} ^Id=(\d+-\d+) [NC]
    RewriteRule ^page/?$ page/%1? [NC,L,R=301]
    

    【讨论】:

      猜你喜欢
      • 2011-02-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-22
      • 2011-03-28
      • 1970-01-01
      相关资源
      最近更新 更多