| |||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | #1 (permalink) |
| Senior Member | htaccess redirect to HTTPS on select pages I'm a complete neophyte at using the .htaccess file, but I know that you can do redirections and stuff with it. Now, I want to switch between http and https depending on what file is requested. If they go to the index of the site (http://www.mysitememberships.com OR http://www.mysitememberships.com/index.php), I want it to stay as http. However, if they go to any of, say 4, specific pages, I want it to switch over to https (pages would be /myadd.php, /myedit.php, /myview.php, /userlogin.php, /controlpanel.php). However, after they visit that page and it switches over to https, I would like it to switch back to http if they request a page that is not part of that list (such as going back to the index). How would I go about doing this?
__________________ Hacksar.com - Your source for random computer tips and tricks! MySiteMemberships.com - Keep track of your site registration information! Like my post? Rep is appreciated! |
| |
| | #3 (permalink) |
| Senior Member | yeah i did it with php, thanks. my solution, put on every page: PHP Code: since it redirects non-https-needed pages back to http, it saves server processing.
__________________ Hacksar.com - Your source for random computer tips and tricks! MySiteMemberships.com - Keep track of your site registration information! Like my post? Rep is appreciated! |
| |
| | #4 (permalink) | |
| NamePros Regular | Quote:
array_search will return FALSE if it does not find a match, so you should use === and !== to test without casting like this: PHP Code: PHP Code: | |
| |
| | #5 (permalink) |
| NamePros Regular | Since the thread I started here (http://www.namepros.com/website-deve...-benefits.html) is evolving into a programming thread, and it is very closely related to this thread, I think I'll post here now with a question. I have the exact code above that qbert has posted: Code: if($_SERVER['HTTPS'] != "on" && in_array(basename($_SERVER['PHP_SELF']), $httpsfile)) {
reload("https://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']);
}
else if(in_array(basename($_SERVER['PHP_SELF']), $httpsfile) && $_SERVER['HTTPS'] == "on") {
reload("http://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']);
}
Edit: I guess I could try a PHP redirect, could I not? This would work just as well, right? Last edited by Rudy; 08-16-2008 at 09:55 AM. |
| |
| | #6 (permalink) |
| Senior Member | oh lol sorry, my bad. i just made a reload function, basically header location. here: PHP Code: edit: just saw your edit, yes it is just a php redirect. i just put it into a function because i used it so many times throughout my site i didn't feel like typing everything out (laziness ftw).
__________________ Hacksar.com - Your source for random computer tips and tricks! MySiteMemberships.com - Keep track of your site registration information! Like my post? Rep is appreciated! |
| |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| |