I'm using .htaccess to force https on certain pages and http on other pages and it's working fine. But I need to force http on home page (example: http://website.com) and I don't know how to do that. I tried RewriteCond %{REQUEST_URI} ^/index.php/? but as I'm using drupal that didn't work.
This is the script I'm using:
RewriteEngine on
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} ^/register/? [OR]
RewriteCond %{REQUEST_URI} ^/admin/?
RewriteRule ^(.*)$ https://website.com/$1 [R,L]
RewriteCond %{SERVER_PORT} 443
RewriteCond %{REQUEST_URI} ^/about-us/? [OR]
RewriteCond %{REQUEST_URI} ^/help/?
RewriteRule ^(.*)$ http://website.com/$1 [R,L]
Any help is appreciated
First, instead of RewriteCond %{SERVER_PORT}, you can use RewriteCond %{HTTPS}, which should be more reliable in detecting HTTPS.
The homepage has the RewriteRule pattern ^$. So the rule would be
RewriteCond %{HTTPS} =on
RewriteRule ^$ http://website.com [R,L]
When everything works as you expect, you can change R to R=301.
Related
I would like to redirect to pages from HTTPS to HTTP using the .htaccess file.
I have added the code for one page but when I add it for page2 it gives the site a redirect error.
Here is my code that works for one page going from HTTPS to HTTP in the .htaccess and I also make sure the .htaccess is in that directory with the files I want to be redirected as well.
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} !^/page1.php$ [NC]
RewriteRule ^(.*)$ https://www.mywebsite.com/$1 [R,L]
RewriteCond %{SERVER_PORT} !80
RewriteCond %{REQUEST_URI} ^/page1.php$ [NC]
RewriteRule ^(.*)$ http://mywebsite.com/$1 [R,L]
But when I add it like this below it doesn't work and I get a redirect error.
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} !^/page1.php$ [NC]
RewriteCond %{REQUEST_URI} !^/page2.php$ [NC]
RewriteRule ^(.*)$ https://www.mywebsite.com/$1 [R,L]
RewriteCond %{SERVER_PORT} !80
RewriteCond %{REQUEST_URI} ^/page1.php$ [NC]
RewriteCond %{REQUEST_URI} ^/page2.php$ [NC]
RewriteRule ^(.*)$ http://mywebsite.com/$1 [R,L]
I would like the pages to go to HTTP only using the .htaccess file without error:
http://mywebsite.com/page1.php http://mywebsite.com/page2.php
I figured it out. The correct code I needed is below:
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} !^/(page2.php$|page1.php$) [NC]
RewriteRule ^(.*)$ https://www.mywebsite.com/$1 [R,L]
RewriteCond %{SERVER_PORT} !80
RewriteCond %{REQUEST_URI} ^/(page2.php$|page1.php$) [NC]
RewriteRule ^(.*)$ http://mywebsite.com/$1 [R,L]
I've got some simple redirect for maintarance mode like:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/index.html$
RewriteCond %{REQUEST_URI} !\.(gif|jpe?g|png|css|js|svg)$
RewriteRule .* /index.html [L,R=302]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
It's working fine.. But when i want to exclude one more URL like:
RewriteCond %{REQUEST_URI} !^/wp-admin($|/)
It's don't redirect properly...
I've add RewriteCond for IP, just for my network.. Work's fine.
RewriteCond %{REMOTE_ADDR} !^123.123.123.123
I have an issue with my .htaccess redirects.
What i want to happen is that all requests to the root, index.php and item.php are redirected to their http equivalent, but every single other page is directed to it's https version.
This is to be used to prevent the slower loading of pages.
Here's what's in my htaccess at the moment:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$ [NC] .
RewriteCond %{REQUEST_URI} !^/(index.php|item.php)
RewriteRule ^(.*)$ https://www.domain.com/$1 [R,L]
RewriteCond %{SERVER_PORT} 443
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$ [NC] .
RewriteCond %{REQUEST_URI} ^/(index.php|item.php)
RewriteRule ^(.*)$ http://www.domain.com/$1 [R,L]
Ideally i need to have an OR inbetween the 2nd and third lines of each collective statement! But i can't work out how to do this!
use [OR] at the end of the 2nd statement.
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$ [NC,OR]
So the problem I am currently having is that our entire website is indexed using https. we want to redirect to http using .htaccess. the problem is that we need a couple of URIs to still use https and I am not sure how to write the exception for URIs
I know the below example would work if our site functioned like this www.example.com/account.php but our site urls are like www.example.com/index.php?l=account
# Turn SSL on for account
RewriteCond %{HTTPS} off
RewriteCond %{SCRIPT_FILENAME} \/account\.php [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
how can i fix this, any guidance would be appreciated.
thanks
EDIT!
So this code below I have working but I would like to make one more exception that I cant seem to get to work, I also want the root (index.php) to only use http.
I tried using...
RewriteCond %{REQUEST_URI} !^/index.php
but this did not work
# invoke rewrite engine
RewriteEngine On
RewriteBase /
RewriteCond %{https} off
RewriteCond %{QUERY_STRING} !^l=product_detail
RewriteCond %{QUERY_STRING} !^l=product_list
RewriteCond %{QUERY_STRING} !^l=page_view
RewriteRule ^(.*)$ https://%{HTTP_HOST}/development/$1 [R=301,L]
thanks
Try
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^/account.php
RewriteCond %{QUERY_STRING} !^l=account
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} ^/account.php [OR]
RewriteCond %{QUERY_STRING} ^l=account
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
I'm trying to force ssl on certain pages, but also on a directory. But I am getting a page loop error. This is my htaccess file:
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} dashboard
RewriteRule ^(.*)$ https://www.example.com/dashboard/$1 [R,L]
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_FILENAME} get_started_lp.php$
RewriteCond %{REQUEST_FILENAME} get_started.php$
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
Basically is someone goes to get_stared_lp or get_started or the dashboard I want SSL. Any suggestions?
Never-mind. It ended up being a issue with how Rackspace handles their SSL. For more information:
http://www.wreckedmagazine.com/jasonsmall/2010/09/14/force-ssl-on-a-rackspace-folder/