本文介绍了RewriteRule-循环重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要这2条重写规则的帮助:

i need help with this 2 rewrite rules:

RewriteEngine On
RewriteBase /

# folder/script.php?A=1&B=2  ->  xyz/1/2 (REDIRECT)
RewriteCond %{QUERY_STRING} ^A=([^&]+)&B=([^&]+)$
RewriteRule ^folder\/script\.php$ /xyz/%1/%2? [R=301,L]

# xyz/1/2  ->  folder/script.php?A=1&B=2 (REWRITE)
RewriteRule ^xyz\/([^\/]+)\/([^\/]+)$ /folder/script.php?A=$1&B=$2 [L]

  • 首先我需要重定向"
    发件人:efectorelativo.net/folder/script.php?A = 1& B = 2
    收件人:efectorelativo.net/xyz/1/2

    • First I need "REDIRECT"
      FROM: efectorelativo.net/folder/script.php?A=1&B=2
      TO: efectorelativo.net/xyz/1/2

      然后我需要重写"而不是重定向"
      来自:efectorelativo.net/xyz/1/2
      收件人:efectorelativo.net/folder/script.php?A=1&B=2

      Then i need "REWRITE" not "REDIRECT"
      FROM: efectorelativo.net/xyz/1/2
      TO: efectorelativo.net/folder/script.php?A=1&B=2

      (工作代码,感谢Gumbo)

      (working code, thanks to Gumbo)

      RewriteEngine On
      RewriteBase /
      
      # folder/script.php?A=1&B=2  ->  xyz/1/2 (REDIRECT)
      RewriteCond %{THE_REQUEST} \?A=([^&]+)&B=([^\s&]+)
      RewriteRule ^folder\/script\.php$ /xyz/%1/%2? [R=301,L]
      
      # xyz/1/2  ->  folder/script.php?A=1&B=2 (REWRITE)
      RewriteRule ^xyz\/([^\/]+)\/([^\/]+)$ /folder/script.php?A=$1&B=$2 [L]
      

      推荐答案

      检查 THE_REQUEST 中的"nofollow>请求行,而不是当前网址:

      Inspect the request line in THE_REQUEST instead of the current URL:

      # folder/script.php?A=1&B=2  ->  xyz/1/2 (REDIRECT)
      RewriteCond %{THE_REQUEST} ^[A-Z]+\ /[^?\ ]*\?A=([^&]+)&B=([^&\ ]+)\
      RewriteRule ^folder/script\.php$ /xyz/%1/%2? [R=301,L]
      

      这篇关于RewriteRule-循环重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 03:47