Hi, i’m new to htaccess, any idea on what i am going to do with my htaccess. First, I want my php pages to be rewriten into html. Secondly, I want some pages/selected pages to be in https. Currently, the code i have will make all pages into https.
Here is my script:
Options -Indexes
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
#Redirect the pages into https:
RewriteCond %{HTTPS} !=on
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
#Rewritting the php pages into html
RewriteRule ^send-inquiry\\.html$ contactus.php
RewriteRule ^user-login\\.html$ user_login.php
RewriteRule ^user-registration\\.html$ user-registration.php
RewriteRule ^company-tradeshow\\.html$ tradeshow.php
RewriteRule ^company-aboutus\\.html$ tradeshow.php
So, if the first 3 url’s is open as http it should automatically be changed into https. Then, if the 2 url(company-tradeshow.html, company-aboutus.html) was open in https it should automatically be change into http.
Any idea for this to work? Any help is much appreciated. Thank you.
I have this htaccess rule below to redirect my login page, contact page and confirmation page into https but the page is isn’t 100%secured because the css and javascript links was not automatically change into https it is still in http. I got SSL warning “warning contains unauthenticated content”.
Are those the only files called by this script? No images linked with absolute links? That’s normally the cause of the unauthenticated content.
OIC, the second part of your mod_rewrite is sending EVERYTHING that’s not one of your three scripts to the http server (port 80) so that’s likely the cause of the problem. Perhaps making that regex into a RewriteCond and the RewriteRule should specify .php for the redirection.
BTW, many thanks for this post as I’d not even considered that effect in my mod_rewrite tutorial. I’ll have to take another look at that section in the morning (after I wake up - I’m exhausted now!).
Okay, you want to rewrite from company/contact-us.html to aboutus.php. No problem, your code will do that just fine.
Unfortunately, your other code block looks … Is the aboutus.php script REALLY the only thing you’ll be sending to HTTPS?
# redirect all HTTPS to HTTPS
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(company/contact-us.html)$ https://%{HTTP_HOST}/$1 [R=301,L]
# redirect company/contact-us.html to aboutus.php here (HIDDEN!)
RewriteRule ^company/contact-us\\.html$ aboutus.php [L]
# redirect all other pages to HTTP
RewriteCond %{REQUEST_URI} !\\.(gif|jpe?g|png|jpe|ico|css|js)$
RewriteCond %{SERVER_PORT} ^443$
RewriteRule !^(company/contact-us.html)$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# What's this tagging along for?
# RewriteCond %{REQUEST_URI} !\\.(gif|jpe?g|png|jpe|ico|css|js)$
BTW, I still think that you’re likely to miss a support file extension more than you’ll miss a PAGE file extension (i.e., .php) so I’d not use the NOT {support file extension list} and match the page file extension, instead.
I still have some other files like the login.php and registration.php. I want to rewrite it too into html like the one i show above and make it redirect into https.
# What's this tagging along for?
# RewriteCond %{REQUEST_URI} !\\.(gif|jpe?g|png|jpe|ico|css|js)$
I used that so i can’t get the SSL warning. Am i doing wrong?
The developer who worked on our site said he used a switch in configuration to determine if CSS etc were on http or https.
The switch when I asked was the difference between using two sets of URLs - one set for local development (http and https) and second set for live site (again http and https).
Your list of “support file” extensions is okay but, if you miss ONE, you’ll break the redirection. IMHO, best to list the file types that you WANT to redirect. Six of one, half dozen of the other, though, so, “if it ain’t broke, don’t fix it.”