views:

232

answers:

2

Hi

I want to one of my site's page will use only HTTPS.

I have given manually link to all sites to https.

But I want that if user manually types that page URL with http then it should be redirected to https page.

So if user types:

http://example.com/application.php

then it should be redirected to

https://example.com/application.php

Thanks
Avinash

+2  A: 

Here's a couple of lines I used in an .htaccess file for my blog, some time ago :

RewriteCond %{HTTP_HOST}  =www.example.com                        
RewriteCond %{REQUEST_URI} ^/admin*                                     
RewriteCond %{HTTPS} !=on                                               
RewriteRule ^admin/(.*)$  https://www.example.com/admin/$1 [QSA,R=301,L]


Basically, the idea here is to :

  • determine whether the host is www.example.com
  • and the URL is /admin/*
    • Because I only wanted the admin interface to be in https
    • which means this second condition should not be useful, in your case
  • and https is off (i.e. the request was made as http)

And, if so, redirect to the requested page, using https instead of http.


I suppose you could use this as a starting point, for your specific case :-)

You'll probably just have to :

  • change the first and last line
  • remove the second one


Edit after the comment : well, what about something like this :

RewriteCond %{HTTP_HOST}  =mydomain.com
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$  https://mydomain.com/$1 [QSA,R=301,L]

Basically :

  • using your own domain name
  • removing the parts about admin
Pascal MARTIN
so what will be code for my problem?
Avinash
A: 

Try this rule:

RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule ^application\.php$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

This rule is intended to be used in the .htaccess file in the document root of your server. If you want to use it in the server configuration file, add a leading slash to the pattern of RewriteRule.

Gumbo