▽1
●
a-kuma3 ●100ポイント ベストアンサー |
RewriteCond の正規表現の後方参照を %1、%2 で使えます。
RewriteRule Directive
...
In addition to plain text, the Substition string can includehttp://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewriterule
- back-references ($N) to the RewriteRule pattern
- back-references (%N) to the last matched RewriteCond pattern
以下のような感じでできるんじゃないでしょうか。
RewriteEngine on RewriteCond %{HTTP_HOST} ^www\.(.*) [NC] RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
質問にある「よくあるサンプル」に合わせましたが、RewriteRule の ^(.*)$ は冗長です。
カッコをつけなくても、$0 で後方参照できますし、
RewriteRule .* http://%1/$0 [R=301,L]
サーバ変数の REQUEST_URI を使えば、後方参照は不要です。
RewriteRule ^ http://%1/%{REQUEST_URI} [R=301,L]
# 速度は変わらないらしいんですけどね