jofitz
jofitz

Reputation: 471

RewriteCond or just RewriteRule for a simple .htaccess re-write?

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]

Upvotes: 1

Views: 205

Answers (1)

Humayun
Humayun

Reputation: 1006

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.

Upvotes: 3

Related Questions