Jake
Jake

Reputation: 3486

Forcing HTTPS for a specific url

How, in htaccess, can you force a URL to be HTTPS at the beginning even if it was specified at HTTP?

E.g. the follwoing urls

/subscribe/spanish
/subscribe/english

I'm assumming there is some kind of regex that can be used with /subscribe at the start?

Upvotes: 0

Views: 58

Answers (1)

anubhava
anubhava

Reputation: 785128

Yes, you can use following rule:

RewriteEngine On

RewriteCond %{HTTPS} off
RewriteRule ^subscribe/ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE,NC]

This will force https if:

  • URI starts with /subscribe/
  • URI has http scheme

Upvotes: 1

Related Questions