以下のように書いて、
<IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{REQUEST_URI} ^/[^/\s]+(/)*$ RewriteRule ^(.*)$ https://google.com [R=301,L] </IfModule>
以下のgif動画でいうところの、赤字部分のリクエストURLの形のときだけgoogle.comにリダイレクトさせる・・・というのをしたいのですが、
![
]
(この動画gifは、https://weblabo.oscasierra.net/tools/regex/で動作させたものです)
RewriteCond に書いている正規表現が間違っているのか、RewriteRule が動いてくれません。
RewriteRule が正常に動作するのは確認済みなので、おそらく正規表現の書き方が間違っていると思うのですが、いくら調べても原因が分かりません。
よろしければご回答のほど、宜しくお願いいたします。
手元のCentOS8のApacheにご質問のrewriteの設定をコピペして動かしてみたところでは、
普通にリダイレクトされています。
問題である
> RewriteRule が動いてくれません。
という点について、何がどう動かないのか、
具体的な例など追記していただけないでしょうか。
```
$ curl -v http://localhost/blog/
* Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 80 (#0)
> GET /blog/ HTTP/1.1
> Host: localhost
> User-Agent: curl/7.61.1
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< Date: Thu, 02 Sep 2021 08:14:01 GMT
< Server: Apache/2.4.37 (centos) OpenSSL/1.1.1g
< Location: https://google.com
< Content-Length: 226
< Content-Type: text/html; charset=iso-8859-1
<
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="https://google.com">here</a>.</p>
</body></html>
* Connection #0 to host localhost left intact
```