Forum Moderators: phranque
2. If already using https then do nothing
3. After any successful RewriteRule or a direct SSl access to adminlogin.php I'd like all other links to default BACK to http:// (no SSL) unless they are specifically referenced their HTML code as a secure link using <a href='https://...
Can anyone see what I'm doing wrong here below?
Thanks
Peter
.htaccess
/*--------------------------------------------------------*/
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
# If HTTPS request - Works! - Needed to put '()' round the RewriteCond filename!
RewriteCond %{HTTPS} on
# redirect non-login requests to HTTP
RewriteCond %{REQUEST_URI} !(adminlogin\.php)
RewriteRule ^(.+)$ [%{HTTP_HOST}...] [R=301,L]
# If not HTTPS request - Works!
RewriteCond %{HTTPS} off
# redirect login requests to HTTPS
RewriteRule ^(adminlogin.php)$ [%{HTTP_HOST}...] [R=301,L]
/*--------------------------------------------------------*/
The only thing I may have changed last night is that on the 1st rule I had previously written [%{HTTP_HOST}%{REQUEST_URI}...] and now I have [%{HTTP_HOST}...] (with the $1).
Would this have made the difference?
PB
Options +FollowSymLinks
RewriteEngine on
#
# If HTTPS request
RewriteCond %{HTTPS} ^on$ [NC]
# redirect non-login requests to HTTP
RewriteCond %{REQUEST_URI} !^/adminlogin\.php$
RewriteRule (.*) http://%{HTTP_HOST}/$1 [R=301,L]
#
# If not HTTPS request
RewriteCond %{HTTPS} ^off$ [NC]
# redirect login requests to HTTPS
RewriteRule ^adminlogin\.php$ https://%{HTTP_HOST}/adminlogin.php [R=301,L]
If this does not help, you might want to look at the browser requests and server responses using the Live HTTP Headers add-on for Firefox/Mozilla browsers. This may give you some insight as to where/when the unexpected redirect is occurring. There is the possibility that you have one or more redirects in the php code itself that are countermanding these in .htaccess.
Also, to the extent possible, correct the links on your site so that pages and object links/URLs refer to the "correct" http/https protocol. If all the links were correct, then you likely wouldn't need this redirect code, except to clean up search engine results for pages that were spidered before the links were corrected, and to catch "type-ins" and bookmarks of incorrect URLs.
Jim
Unfortunately, the redirects are necessary because people don't type [,...] they just type the domain name and hit enter which defaults in most browsers to http://
Again, thanks a lot. I love your site by the way, the help is in-valuable!
Peter B