teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

2

そうか。クエリを消さないとループしますね。

2018/07/12 05:55

投稿

rogueref
rogueref

スコア727

answer CHANGED
@@ -3,7 +3,7 @@
3
3
  ```
4
4
  RewriteCond %{QUERY_STRING} .*
5
5
  RewriteCond %{HTTPS} on
6
- RewriteRule .* https://www.example.com/bbb/ccc.html [R,L]
6
+ RewriteRule .* https://www.example.com/bbb/ccc.html? [R,L]
7
7
 
8
8
  ```
9
9
 
@@ -12,13 +12,14 @@
12
12
  (追記)
13
13
  クエリ文字列によってリダイレクト先を変えたいとのこと。
14
14
  クエリ文字列とリダイレクト先URIが一致しているのならバックリファレンスを使えます。
15
+ あと、クエリを消さないとリダイレクトがループします。
15
16
  https://www.example.com/?xxx=123 を
16
17
  https://www.example.com/bbb/123.html へリダイレクトするなら以下のような感じ。
17
18
 
18
19
  ```
19
20
  RewriteCond %{QUERY_STRING} xxx=(\d+)
20
21
  RewriteCond %{HTTPS} on
21
- RewriteRule .* https://www.example.com/bbb/%1.html [R,L]
22
+ RewriteRule .* https://www.example.com/bbb/%1.html? [R,L]
22
23
  ```
23
24
 
24
25
  クエリ文字列とリダイレクト先URIになんの関係もないのなら、一つづつ書くしかありません。

1

コメントから追加要求仕様。

2018/07/12 05:55

投稿

rogueref
rogueref

スコア727

answer CHANGED
@@ -3,8 +3,22 @@
3
3
  ```
4
4
  RewriteCond %{QUERY_STRING} .*
5
5
  RewriteCond %{HTTPS} on
6
- RewriteRule .* https://www.aaa.com/bbb/ccc.html
6
+ RewriteRule .* https://www.example.com/bbb/ccc.html [R,L]
7
7
 
8
8
  ```
9
9
 
10
- うまく行かなかった場合は、試したことも質問内容にかくといいでしょう。
10
+ うまく行かなかった場合は、試したことも質問内容にかくといいでしょう。
11
+
12
+ (追記)
13
+ クエリ文字列によってリダイレクト先を変えたいとのこと。
14
+ クエリ文字列とリダイレクト先URIが一致しているのならバックリファレンスを使えます。
15
+ https://www.example.com/?xxx=123 を
16
+ https://www.example.com/bbb/123.html へリダイレクトするなら以下のような感じ。
17
+
18
+ ```
19
+ RewriteCond %{QUERY_STRING} xxx=(\d+)
20
+ RewriteCond %{HTTPS} on
21
+ RewriteRule .* https://www.example.com/bbb/%1.html [R,L]
22
+ ```
23
+
24
+ クエリ文字列とリダイレクト先URIになんの関係もないのなら、一つづつ書くしかありません。