301 permanent redirection except secure domain

Discussions of secure PHP coding. Security in software is important, so don't be afraid to ask. And when answering: be anal. Nitpick. No security vulnerability is too small.

Moderator: General Moderators

Post Reply
basudeb
Forum Commoner
Posts: 44
Joined: Wed Dec 20, 2006 12:13 am

301 permanent redirection except secure domain

Post by basudeb »

My site url is http://mydomain.com but in payment section the url is secured(shared). I want to redirect from http://mydomain.com to http://www.mydomain.com .But the payment pages the urls should be same as it is . How can set the Rewrite rule for .htacess files.. Need Some suggestion ...
User avatar
kaisellgren
DevNet Resident
Posts: 1675
Joined: Sat Jan 07, 2006 5:52 am
Location: Lahti, Finland.

Re: 301 permanent redirection except secure domain

Post by kaisellgren »

jceresini
Forum Newbie
Posts: 8
Joined: Fri Mar 27, 2009 6:03 pm

Re: 301 permanent redirection except secure domain

Post by jceresini »

This will redirect anyone who accesses your site on port 80 to the https site and keep them on the same page they attempted to visit.

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]

Joe Ceresini
Network Engineer
jceresini@hostmysite.com
HostMySite.com
gregor171
Forum Newbie
Posts: 22
Joined: Thu Apr 16, 2009 5:09 pm
Location: Ljubljana, Slovenia

Re: 301 permanent redirection except secure domain

Post by gregor171 »

you can simply redirect it by checking where request came from
$_SERVER['SERVER_NAME']

to see if it's https:
$_SERVER['HTTPS']

and redirect it with header() function.
Post Reply