Https

Fix it!!

Https

Postby deniz » Thu Dec 06, 2007 7:02 am

Hello all,

I want to make a rewrite rule with mod_rewrite which will automaticly move a specific url from http to https for only one location..

Example:
When user put the following url on their browser: http://mywebsite.com/accounts.php?accou ... ient_id=FF

It must be redirected to:
https://mywebsite.com/accounts.php?accountkey=52533AQC&client_id=FF

Something like this;
Code: Select all
RewriteEngine on

    RewriteOptions inherit

    RewriteCond %{SERVER_PORT}      !^443$

    RewriteRule ^/accounts.php(.*) https://%{SERVER_NAME}/accounts.php [L,R]


Is ahove rule correct?
deniz
 
Posts: 3
Joined: Thu Dec 06, 2007 6:58 am

Postby richardk » Fri Dec 07, 2007 1:35 pm

All /accounts.php?* URLs? Where are you going to put it?

Try the following in a .htaccess file in your document root
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^accounts\.php$ https://%{HTTP_HOST}/accounts.php [NC,R,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby deniz » Fri Dec 07, 2007 2:02 pm

richardk wrote:All /accounts.php?* URLs? Where are you going to put it?

Try the following in a .htaccess file in your document root
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^accounts\.php$ https://%{HTTP_HOST}/accounts.php [NC,R,L]


accounts.php with $_GET values.. http://mywebsite.com/accounts.php?accou ... ient_id=FF
deniz
 
Posts: 3
Joined: Thu Dec 06, 2007 6:58 am

Postby richardk » Fri Dec 07, 2007 2:35 pm

accounts.php with $_GET values

Should do what? Is it only supposed to match if there is a query string? Only those exact key/value pairs? Only those keys? Be specific.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby deniz » Fri Dec 07, 2007 4:43 pm

richardk wrote:
accounts.php with $_GET values

Should do what? Is it only supposed to match if there is a query string? Only those exact key/value pairs? Only those keys? Be specific.


Sorry.. It's only supposed to match if there is a query string.. once it detect a query string it must be automaticly convert it.. see below..

something like this;
Code: Select all
RewriteCond %{SERVER_PORT}      !^443$
    RewriteRule ^/account.php(.*) https://%{SERVER_NAME}/account.php$1 [L,R]


example:
http://mysite.com/account.php?blala=bla ... ptc=fdsdfd

https://mysite.com/account.php?blala=bl ... ptc=fdsdfd

as you may have seen only following line changed from http to https
deniz
 
Posts: 3
Joined: Thu Dec 06, 2007 6:58 am

Postby richardk » Fri Dec 07, 2007 4:57 pm

So you want it to match any query string?
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{SERVER_PORT} !^443$
RewriteCond %{QUERY_STRING} !^$
RewriteRule ^accounts\.php$ https://%{HTTP_HOST}/accounts.php [NC,R,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Security with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 24 guests

cron