HTTPS to HTTP htaccess redirect for home page only

2019-08-07 02:36发布

问题:

I need help being able to redirect the home page of a website I'm building from HTTPS to HTTP.

The website I'm building is using cart 66 and unfortunately when the site redirects back to the home page after visiting the secure cart pages it stays in HTTPS and certain elements of the front page no longer display correctly.

I assume doing a redirect will be the best option to solve this problem. Although I'm open to other suggestions.

I've searched for solutions online, but I can only find redirects from HTTPS to HTTP for the whole site, not just a single page or the opposite of what I'm trying to do. I'm too much of a noob with htaccess to try and reverse engineer a solution from the bits and bobs I can find.

I'd also like to leave the option of adding more than one page to the redirect just in case I discover any more pages that end up appearing broken.

Any help is greatly appreciated.

回答1:

As suggested on apache wiki:

http://wiki.apache.org/httpd/RewriteHTTPToHTTPS

you could use:

RewriteEngine On
# This will enable the Rewrite capabilities

RewriteCond %{HTTPS} on
# This checks to make sure the connection is HTTPS

RewriteRule ^/?homepage\.html http://%{SERVER_NAME}/homepage\.html [R,L]

changing homepage.html to your home page name.