Jump to content

.htaccess and https and URL routing


tcnjdeluca

Recommended Posts

I am attempting set up my server so I can have both URL routing and direct one or two pages to https automatically. 

 

I set my .htaccess to the following and redirected all my pages to https, but broke some of my URL routing.

	Options +FollowSymLinks
IndexIgnore */*
# Turn on the RewriteEngine
RewriteEngine On
#  Rules
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . homepage.php
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.classchatterlive.com/$1 [R,L]
AddType application/x-httpd-php .xml

 

I do not need every page on the site to be redirected to https, if there is a way to only redirect specific pages, that would work for me as well.

 

Thanks for your help:

 

Link to comment
https://forums.phpfreaks.com/topic/137126-htaccess-and-https-and-url-routing/
Share on other sites

Well seems like it would be something to take care of on the server with .htaccess, but is there anything wrong with redirecting with a little php like this

$requireSSL = true;
// If page requires SSL, and we're not in SSL mode, 
// redirect to the SSL version of the page
if($requireSSL && $_SERVER['SERVER_PORT'] != 443) {
   header("HTTP/1.1 301 Moved Permanently");
   header("Location: https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
   exit();
}

 

Thats not my code I found it  at http://www.somacon.com/p536.php, but it seems simple and effective enough.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.