Arta S
Arta S

Reputation: 134

How to combine orders in htaccess

I have a few specific pages in my website which I need to force SSL. The code I have works fine but it made the length of the codes too large in .htaccess file.

Is there a way to combine all these pages into a smaller code?

This is the code that I right now have:

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteCond %{REQUEST_URI} clientarea.php
RewriteRule ^(.*)$ https://example.com/$1 [R,L]

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteCond %{REQUEST_URI} submitticket.php
RewriteRule ^(.*)$ https://example.com/$1 [R,L]

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteCond %{REQUEST_URI} contact.php
RewriteRule ^(.*)$ https://example.com/$1 [R,L]

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteCond %{REQUEST_URI} cart.php
RewriteRule ^(.*)$ https://example.com/$1 [R,L]

So i have file pages clientarea.php , submitticket.php , contact.php and cart.php

How can I combine them all into one code instead of 4 of the same?

Thank you

Upvotes: 1

Views: 40

Answers (1)

Amit Verma
Amit Verma

Reputation: 41229

To force https for specific pages, you can use this :

RewriteEngine on
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(page1|page2|page3)/?$ https://example.com/$1 [R,L]

You can include multiple pages to the rule's pattern, just separate them by a pipe | char.

Upvotes: 1

Related Questions