Unstoppable Domains โ€” Expired Auctions

Quick PHP https to http redirect question

Namecheap AuctionsNamecheap Auctions
Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
Watch
Impact
14
Hello,

I wrote(attempted) to write a script to detect if the user was coming in on 80 or 443, and if 80 it would do a header redirect to HTTPS.

I can't test it ATM, and I wanted to add this to a script.

Can someone tell me if this works, or test it for me?

if($HTTPS != 'on') {
header("Location: https://".$HTTP_HOST."/".$REQUEST_URI);
}

phpinfo()


Basically if the script works, it'll show the basic phpinfo() page but instead of being on http, it'll be on https.


Simple, but i'm a newb anyways.


Thanks for the help if you can, will +rep!


~brandon
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Why not use a .htaccess file

Code:
RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.site.com/$1 [R,L]
 
0
•••
Hmm i like that, but oh well. i have figured out the solution,

TY anyways :)


brndon
 
0
•••
.htaccess is a better way to go
 
0
•••
I'll throw another vote in for using an htaccess instead, it's a much better way to go.
 
0
•••
I agree, but the point of this was to learn how to do this in PHP.

Appreciate the help though, guys.
 
0
•••
i have figured out the solution

Care to share for the benefit of others?

.htaccess may not always be the most efficient, especially if you have to enable AllowOverrides in your Apache config for it.
 
0
•••
Dynadot โ€” .com TransferDynadot โ€” .com Transfer
CatchedCatched
Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
DomDB
NameFit
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back