Forum Moderators: phranque
RewriteEngine On
RewriteCond %{SERVER_PORT}!^443$ [OR]
RewriteCond %{HTTP_HOST}!^www\.domain\.com [NC]
RewriteRule ^(.*)$ https://www.domain.com/secure/$1 [R,L]
I goto http://www.domain.com/secure/ and it takes me to https://www.domain.com/secure/
However, when I go to http://www.domain.com/secure
It redirects me to https://www.domain.com/secure//home/username/public_html/secure
Also, when I goto http://www.domain.com/secure/anotherpage
It takes me to https://www.domain.com/secure/anotherpage
which is correct.
I basically want to make all URLs on the /secure folder to use https instead of http.
--
Also, I would like to make a condition, where when the address is http://www.domain.com/secure/another-page-thats-not-secure.php to not rewrite to https
This is just one page that needs to be unsecure.
------------------------------------------
#turn on the engine
RewriteEngine On
#first, correct the www if necessary
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]
RewriteRule ^(.*)$ [domain.com...] [R=301]
#then, rewrite secure folder 1
RewriteCond %{REQUEST_URI} !^/helpdesk/admin/parser.php [NC]
RewriteCond %{REQUEST_URI} ^/helpdesk/ [NC]
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ [domain.com...] [R=301,L]
#then, rewrite secure folder 2
RewriteCond %{REQUEST_URI} ^/modernbill/ [NC]
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ [domain.com...] [R=301,L]
#then, rewrite slashes for secure folder 1
RewriteCond %{REQUEST_URI} ^/helpdesk [NC]
RewriteCond %{REQUEST_URI} !^/helpdesk/ [NC]
RewriteRule ^(.*)$ [domain.com...] [R=301,L]
#then, rewrite slashes for secure folder 2
RewriteCond %{REQUEST_URI} ^/modernbill [NC]
RewriteCond %{REQUEST_URI} !^/modernbill/ [NC]
RewriteRule ^(.*)$ [domain.com...] [R=301,L]
------------------------------------------
And it works!
[domain.com...] > [domain.com...]
[domain.com...] > [domain.com...]
--
Oh, and thanks for the help claus :)
FrontPage forms will not work when this is on. The problem occurs with the _vti_bin/ folder.
If I comment out all of the code (except for the RewriteEngine On part) the script still fails.
So basically only when the RewriteEngine is on, it will fail. If I turn it off, it works fine.
Any work around for this?
If, OTOH, it is a conflict of rules, then you could add this condition to the top of all the blocks of rules:
RewriteCond %{REQUEST_URI} !^/_vti_bin [NC] Example:
----------------------------------------------
#then, rewrite secure folder 1
RewriteCond %{REQUEST_URI} !^/_vti_bin [NC]
RewriteCond %{REQUEST_URI} !^/helpdesk/admin/parser.php [NC]
RewriteCond %{REQUEST_URI} ^/helpdesk/ [NC]
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ [domain.com...] [R=301,L]
----------------------------------------------
This simply says that the rewrite rule should not work for an URL that starts with "your-domain.com/_vti_bin".