Forum Moderators: phranque

Message Too Old, No Replies

force some folder and file to https working but not look scure in FF

         

tutdeden

7:05 am on Mar 5, 2010 (gmt 0)

10+ Year Member



I use script as below on my .htaccess:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

RewriteCond %{SERVER_PORT} =80
RewriteCond %{REQUEST_URI} (admin|home\.php$)
RewriteRule ^(.*)$ [example.com...] [R=301,L]

RewriteCond %{SERVER_PORT} =443
RewriteCond %{REQUEST_URI} !(admin|home\.php$)
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]



above script is work but not lock the secure at URL address bar.

if i do like this will work perfectly:

~~~~~blablabla~~~~~

RewriteCond %{SERVER_PORT} =80
RewriteCond %{REQUEST_URI} admin
RewriteRule ^(.*)$ [example.com...] [R=301,L]

~~~~~blablabla~~~~~

it will force any on admin folder only to https, but i need it done not only for admin folder.
===

Actually i want to redirect some folder and some file to https but with the perfect result, i mean shown the blue or green on url address bar.

I hope somebody can help me... it's very confusing... :(

g1smd

7:57 am on Mar 5, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I suspect that the $ inside the parentheses is confusing the matter.

tutdeden

8:17 am on Mar 5, 2010 (gmt 0)

10+ Year Member



Thanks g2smd for your reply,

I've tried to make something like this: (admin|home\.php)$
but it's still make a green/blue at the url address bar appears only one second and then disappear again.

I do not know what caused it.

with only redirect one directory to https it's work perfectly, but that's not what I expected.

i want to get done with some directories and some files and with the green or blue sign on url address is always appear, so user can trust to shop using my website.

====
example.com/admin/ ----> force to https
example.com/home.php$ ---> force to https

else ---> force to http
====

sorry with my english,
and i'am new on .htaccess, don't know much about htaccess.

i need yours help,
thanks in advance

cheers,

Deden

jdMorgan

9:40 pm on Mar 5, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It is perfectly-acceptable to put the "$" inside parentheses, and here it's required if you wish the RewriteCond to match a Request URI of exactly "/index.php" or any request in the "/admin" directory-path.

The problem appears to be your domain canonicalization rule, which always forces non-SSL "http:", combined with a rule-order problem and a few logic and regular expressions problems in the other rules.

If --and this "if" is important, both your SSL and non-SSL request resolve to this .htaccess file's directory as DocumentRoot, then this might work better:

RewriteEngine on
#
RewriteCond %{SERVER_PORT} [b]!=443[/b]
RewriteCond %{REQUEST_URI} [b]^/([/b]admin/|home\.php$)
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
#
RewriteCond %{SERVER_PORT} !=80
RewriteCond %{REQUEST_URI} ![b]^/([/b]admin/|home\.php$)
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
#
RewriteCond %{HTTP_HOST} ^example\.com
[b]RewriteCond %{SERVER_PORT}>s ^(443>(s)|[0-9]+>s)$[/b]
RewriteRule [b]^(.*)$ http%2://[/b]www.example.com/$1 [R=301,L]

You need to be very sure that within your own site, you only link to the canonical "www" hostname, and that all links are correct with regard to whether the linked resource is http or https; While mod_rewrite can help search engines correct any incorrect URLs in their search results listings resulting from bad links posted on other sites, it won't really help if you have linking errors on your own site. Don't try to rely on a redirect as a "quick fix" for linking errors on your own pages.

Jim

tutdeden

2:39 am on Mar 8, 2010 (gmt 0)

10+ Year Member



wow, I become know about htaccess a little bit more now..

That's work! Thanks Jim, and i love replay that really help me from you all.

Cheers,

Deden