一部の特定のページについてのみ、www / http以外をwww / httpsに強制します
特定のページをwww / http以外からwww / httpsに強制し、他のページをwww / http以外のままにしておくことができるのではないかと思っていました。
例
www / http以外からwww / httpsへ:
http://example.com に https://www.example.com
しかし、これらのものは非wwwとhttpのままになります:
http://example.com/folder1/*
http://example.com/folder2/*
私はhtaccessファイルにこのルール条件を追加しようとしました:
RewriteEngine On
# Enable HTTPS and WWW for homepage
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{HTTPS} off
RewriteRule ^$ https://example.com/ [R=301,L]
# Disable HTTPS and WWW for all pages
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{HTTPS} on
RewriteRule . http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
次に、ホームページだけをhttpsとwwwに強制し、/ folder1 /や/ folder2 /などの他のページをhtpp非wwwのままにします。
しかし、それはうまく機能していないようです
回答
murataka
これらを試してください:
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule ^folder1.*$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] RewriteEngine On RewriteCond %{HTTPS} on RewriteRule ^folder2.*$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule ^folder1.*$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] RewriteEngine On RewriteCond %{HTTPS} on RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^folder2.*$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] RewriteEngine On RewriteCond %{HTTPS} on RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^folder1.*$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
等々...
ΔO'deltazero'
これを試して:
RewriteEngine On
RewriteCond %{HTTPS} off ## http requests only
RewriteRule ^folder1/ - [L] ## stop for folder1/
RewriteRule ^folder2/ - [L] ## stop for folder2/
## then redirect all other requests:
RewriteRule ^(.*)$ https://www.example.com%{REQUEST_URI} [END,NE,R=permanent]
同様に、スキップを正規表現できます。
RewriteRule ^folder(\d+)/ - [L] ## stop redirection for any folder[number]/
または、これをネガティブにしRewriteCond
て、シングルを維持しRewriteRule
ます:
RewriteEngine On
RewriteCond %{HTTPS} off ## http requests only
RewriteCond %{REQUEST_URI} !^/folder(\d+)/ ## skip any folder[number]/
RewriteRule ^(.*)$ https://www.example.com%{REQUEST_URI} [END,NE,R=permanent]
など...完全なドキュメント: https://httpd.apache.org/docs/2.4/rewrite/flags.html