开发者

How to properly force HTTPS on specific pages using Apache

开发者 https://www.devze.com 2023-03-09 21:32 出处:网络
I would like to force my signup page to https, and allow all other pages to be browsed using https or http (e.g., http://www.example.com/signup should redirect to https://www.example.com/signup). I wa

I would like to force my signup page to https, and allow all other pages to be browsed using https or http (e.g., http://www.example.com/signup should redirect to https://www.example.com/signup). I was able to force all pages to https, but cannot get only one page to redirect to https. The page just loads normally as http.

Here's the code I've been trying t开发者_开发问答o use in my htaccess file:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^/signup(/.*)$ https://www.example.com/$1 [R=301,L]

For what it's worth (in case there is a conflict I'm unaware of), I am also using the following code to force all pages to redirect to www and to drop the .php from the file names in the URL:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^([a-z.]+)?example\.com$ [NC]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .? http://www.%1example.com%{REQUEST_URI} [R=301,L]

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php?/$1

Any thoughts on what I'm doing wrong?


Have your https rule like this:

RewriteCond %{SERVER_PORT} =80
RewriteRule ^(signup/?)$ https://www.example.com/$1 [R=301,L,NC]

Remember that there is no starting slash / in RewriteRule.

0

精彩评论

暂无评论...
验证码 换一张
取 消