-2

Possible Duplicate:
Force SSL/https using .htaccess and mod_rewrite

On my site I'm planning on using multiple domains, some may have SSL, some may not. I'd like to force the SSL ones to use it, and the non to not. Is this possible? I think I'd need to use PHP, but maybe this can be done in .htaccess. Any help? How about if I let my customer enter it, like they could say they'd like their url to start with https://www or just http://, is there a way to create a permenant redirect using php? Sorry kinda newbish questions for someone who builds such indepth cms'. Also, quick question: are there any drawbacks to the route-all-to-index.php style of creating permalinks that i've been using as far as performance is concerned?

Community
  • 1
  • 1
HTMLGuy
  • 245
  • 2
  • 17
  • I didn't see that one before because due to the title, I thought it only applied to one that you KNOW has ssl. Obviously I was searching for "force ssl if available". Thank you Gordon. – HTMLGuy Jan 25 '13 at 14:25
  • Gordon, any idea if there are drawbacks to .htaccess redirecting all to index.php? – HTMLGuy Jan 25 '13 at 18:36
  • it gets parsed on each Request which can slow down the site and your devs need to know how to configure it. – Gordon Jan 25 '13 at 22:12
  • pretty much needs to be parsed anyway considering it needs to break apart the url to figure out which site (and template, and page [based on permalink]) to display. I'm wondering how to speed that up. It needs to find the permalink each time regardless, so it doesn't slow it down any to use the domain each time to grab the site row right? My structure is as follows: Route all to index.php, Break apart URL, Find website or echo 404, Find page or echo 404, Set the rest of the parameters as the $_GET array, Grab page + widgets, Convert shortcodes, Display it all. Any way to optimize? – HTMLGuy Jan 25 '13 at 22:58

1 Answers1

0

Try this:

if ($_SERVER["HTTPS"] != "on") {
  header("Location: https://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
}
Rob
  • 1,840
  • 2
  • 12
  • 19
  • Won't that have to redirect each time they visit the page? Obviously I want to make the SEO the best I can with a perm. redirect. – HTMLGuy Jan 25 '13 at 14:24
  • No, it will handle it once and every request after that will use https – Rob Jan 25 '13 at 14:27