Forum Moderators: phranque

Message Too Old, No Replies

need to apply a RewriteRule to specific files to force https

         

qhrome27

12:12 am on Sep 17, 2009 (gmt 0)

10+ Year Member



hello,

I have a few specific PHP files in a folder, which when visited, the .htaccess file should force https instead of http.

How do I target those 3 specific PHP files?

For another folder, to force https the whole folder, I am using:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} admin
RewriteRule ^(.*)$ [domain.com...] [R,L]

I imagine it will be similar to this, but changed to target just those files?
Please give me a sample of what it would take to target specific PHP files and force it to https.

Thanks.

qhrome27

1:11 am on Sep 17, 2009 (gmt 0)

10+ Year Member



I ended up reading the whole URL with PHP, and exploding it at "://".

If the 1st item in the created array was "http" I redirect it to the same URL, but starting with "https".

I just run that function on each page I want to force https.

Not sure if that is the best way.

jdMorgan

3:48 am on Sep 17, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



"The best way" is the way that you understand and can maintain over time -- Which is why we try to focus on discussion and specific questions about existing code instead of "writing code for people" here, and why I don't recommend using code copied from elsewhere unless you understand it completely.

So, I'd say you found the best way. :)

[added] And do be sure you're sending a 301-Moved Permanently redirect response, and not a 302. Otherwise, the search engiens will never figure out that your SSL pages should always be listed and linked with an https-protocol URL. [/added]

Jim