web-dev-qa-db-ja.com

mod_rewriteループ、wordpressブログの特定のセクションでhttpをhttpsにリダクションする

私は彼らがhttp経由でアクセスされている場合は、ワードプレスサイトの3つのセクションをhttpsに書き換えようとしています。

/cart/

/my-account/

/checkout/

これらの書き換えの最悪の事と同様にurlからindex.phpを削除するための書き換えを追加しました。 index.phpの書き換えは、動作している唯一のものです。これが私の.htaccessです。

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} (checkout|cart|my-account)
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=302,L]

# BEGIN WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress

</IfModule>

# END WordPress

いくつかのカールテスト

以下では、http:/ cartへのアクセスがこれがhttps/cartへ移動したことを正しく伝えているのを見ることができます、それで私はそれが全く同じhttpsバージョンへ移動したと言われてループ。

PS C:\Users\Stephen> C:\Users\Stephen\Downloads\curl-7.23.1-win64-ssl-sspi\curl.exe -k -i http://www.mysite.com/cart
HTTP/1.1 302 Found
Date: Wed, 20 Feb 2013 09:07:06 GMT
Server: Apache
Location: https://www.mysite.com/cart
Vary: Accept-Encoding
Content-Length: 285
Content-Type: text/html; charset=iso-8859-1

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>302 Found</title>
</head><body>
<h1>Found</h1>
<p>The document has moved <a href="https://www.mysite.com/cart">here</a>.</p>
<hr>
<address>Apache Server at www.mysite.com Port 80</address>
</body></html>

PS C:\Users\Stephen> C:\Users\Stephen\Downloads\curl-7.23.1-win64-ssl-sspi\curl.exe -k -i https://www.mysite.com/cart
HTTP/1.1 302 Found
Date: Wed, 20 Feb 2013 09:07:06 GMT
Server: Apache
Location: https://www.mysite.com/cart
Vary: Accept-Encoding
Content-Length: 285
Content-Type: text/html; charset=iso-8859-1

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>302 Found</title>
</head><body>
<h1>Found</h1>
<p>The document has moved <a href="https://www.mysite.com/cart">here</a>.</p>
<hr>
<address>Apache Server at www.mysite.com Port 80</address>
</body></html>

それはhttpsにリダイレクトしますが、それからループで動けなくなり、ブラウザはループを訴えます。書き換えの達人は誰でもここにいます。

1
0x7c0

私は決してmod_rewriteのエキスパートではありませんが、このようなことをしたいと思いますか?

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

# Force HTTPS for /cart/
RewriteCond %{HTTPS} !=on
RewriteCond %{THE_REQUEST} ^[A-Z]+\s/cart [NC]
RewriteRule ^(cart) https://%{HTTP_Host}%{REQUEST_URI} [NC,R=301,L]

# Force HTTPS for /my-account/
RewriteCond %{HTTPS} !=on
RewriteCond %{THE_REQUEST} ^[A-Z]+\s/my-account [NC]
RewriteRule ^(my-account) https://%{HTTP_Host}%{REQUEST_URI} [NC,R=301,L]

# Force HTTPS for /checkout/
RewriteCond %{HTTPS} !=on
RewriteCond %{THE_REQUEST} ^[A-Z]+\s/checkout [NC]
RewriteRule ^(checkout) https://%{HTTP_Host}%{REQUEST_URI} [NC,R=301,L]

# BEGIN WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress

</IfModule>

# END WordPress

私は3つの別々のステートメントをどうにか組み合わせることができると確信しています、しかし私が言ったように私は専門家ではありません。これがあなたのために適切に機能するかどうか私に知らせてください。

1
Josh Mountain