| | |||||
| ||||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| Senior Member Join Date: Jul 2005 Location: NJ
Posts: 1,219
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | 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). ????: NamePros.com http://www.namepros.com/programming/498820-htaccess-redirect-to-https-select-pages.html 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! |
| |
| | THREAD STARTER #3 (permalink) |
| Senior Member Join Date: Jul 2005 Location: NJ
Posts: 1,219
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | 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 Join Date: Jul 2007 Location: UK
Posts: 395
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
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 Join Date: Jul 2005 Location: United States
Posts: 586
![]() ![]() ![]() ![]() | 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']);
} ????: NamePros.com http://www.namepros.com/showthread.php?t=498820 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 10:55 AM.
|
| |
| | THREAD STARTER #6 (permalink) |
| Senior Member Join Date: Jul 2005 Location: NJ
Posts: 1,219
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | 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! |
| |