I have my page at a shared host. In general the site is reachable using http and https. The page serves ads and most of the ads are not available using https therefore I only want the admin parts to be reachable via https.

What I want is:

http://myurl.com/auth -> https://myurl.com/auth
http://myurl.com/admin -> https://myurl.com/admin

https://myurl.com/allotherstuff -> http://myurl.com/allotherstuf

Basically all requests to auth and admit should be redirected to use ssl. Requests to other sites should be redirected from https to http (if the page is requested using https).

I tried the following .htaccess file, which makes "auth" and "admin" unreachable (too many redirects).

<IfModule mod_rewrite.c>    
    RewriteEngine On

#Redirect other sites to http
    RewriteCond %{HTTPS} =on
    RewriteCond %{REQUEST_URI} !^/?auth.*$
    RewriteCond %{REQUEST_URI} !^/?admin.*$
    RewriteRule ^/?(.*) http://%{SERVER_NAME}/$1 [R,L]


#Redirect auth and admin to https

    RewriteCond %{HTTPS} !=on
    RewriteRule ^/?auth/(.*) https://%{SERVER_NAME}/auth/$1 [R,L]

    RewriteCond %{HTTPS} !=on
    RewriteRule ^/?admin/(.*) https://%{SERVER_NAME}/admin/$1 [R,L]

</IfModule>

Is it possible to accomplish this using mod_rewrite?

Ok , if want http to https then please install self sing certificate

  • The site is reachable via both http and https. A certificate is available. But I want certain parts of the page only be reachable via http and other parts only be reachable via https. – stefa Jan 19 '16 at 8:39

You can add this code in .htaccess file

      <IfModule mod_rewrite.c> 
         RewriteEngine on     
        RewriteCond %{HTTP_HOST} ^tset.com/tset$ [NC]  
        RewriteRule ^/?$ "https://test.com/test" [R=301,L]
       </IfModule>
  • Thanks for the answer. I can only use .htaccess files (shared hosting provider). Therefore this solution won't work. – stefa Jan 18 '16 at 12:21
  • Updated please check and let me know – mohit singh Jan 18 '16 at 12:36
  • Thanks for the update. I tried it, but it doesn't work. I'd like to have some sites redirected from https to http and others from http to https. – stefa Jan 19 '16 at 6:53

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.