1

I am composing a simple .htaccess re-write to force a single page to use https (inspired by the answers to this question).

Is it better to use RewriteCond, as follows:

RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} ^/page\.php$
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

or the shorter alternative with the condition in the RewriteRule:

RewriteCond %{HTTPS} off
RewriteRule ^page\.php$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
Community
  • 1
  • 1
jofitz
  • 459
  • 1
  • 3
  • 12
  • I think both should work in your case, there's no much difference in both. – Humayun Oct 31 '12 at 12:47
  • @humayun I can confirm that both _do_ work. I am wondering if there is any reason to use the former, longer version. Also, if anyone can make any improvements then please do – jofitz Oct 31 '12 at 14:06

1 Answers1

3

Well, if you are using apache as your httpd server then you are absolutely fine and safe with the single condition and single rule which is enough to achieve your given task. There's no advantage using former over shorter one. I say if you don't have to make/apply further rules or checks then use the shorter one rather than applying one more extra condition. I'm saying this because your situation is rather simple, you just have to redirect to https for only one given page.

Even if you look at AskApache site here they also suggest the best way is to just use %{HTTPS} variable along with one single RewriteRule which is best and efficient way.

Let me know if your concerns are different than what I mentioned above.

Community
  • 1
  • 1
Humayun
  • 976
  • 7
  • 13