My problem is that when I try to access the some file, for example
http://domain.com/myFile.php?Key1=Value1&Key2=Value2
Sometimes it works, and sometimes it redirects me to:
https://domain.commyfile.php/?Key1=Value1&Key2=Value2
this problem started after I added TLS to the site (redirecting http to https works fine, But this problem showed up).
my .htaccess file:
# Do not remove this line or mod_rewrite rules and search engine friendly URLs will stop working
RewriteBase /
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://mydomain$1 [R,L]
RewriteEngine On
RewriteCond %{HTTPS} on
can anyone tell me why does it happen?
You need to change the RewriteRule because the base is /. Do the following:
RewriteBase /
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://mydomain/$1 [R,L]
RewriteEngine On
RewriteCond %{HTTPS} on
Related
After a long R&D process, I am here with an unresolved issue of WordPress redirection. None of the available resources helped me really.
What I need is -
I have successfully redirected my entire WP site and admin to HTTPS.
Now, I need one specific page to redirect to HTTP only. Because I will be using iframe on that page to load external sites for preview.
My requested url should be like this -
http://example.com/live-preview/?product_id=(number like 1,2,3 etc)
I want the above url(s) to load without HTTPS.
My present htaccess file is this -
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*) https://%{SERVER_NAME}/$1 [R=301,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
So anything with (/live-preview/) should be on HTTP only. Please help me how I will be able to do this.
Thank you so much.
-Amit
After a long investment of time and many researches, I manage to fix this issue with my code. I am sharing this for public interest.
This is the working htaccess code -
RewriteCond %{HTTPS} !on
RewriteCond %{QUERY_STRING} !^product_id=(.*)$
RewriteRule ^(.*)$ https://%{SERVER_NAME}/$1 [R=301,L]
RewriteCond %{HTTPS} on
RewriteCond %{QUERY_STRING} ^product_id=(.*)$
RewriteRule ^(.*)$ http://%{SERVER_NAME}/$1 [R=301,L]
So I have to use {QUERY_STRING} and use 2 conditions with 301 permanent redirection.
I'm trying to redirect all webpages to https for my wordpress app which is hosted on heroku. I'm using the Wordpress HTTPS plugin, and I've succeeded in getting all the wordpress pages to redirect to https, but my custom pages do not redirect. The app is setup using this template. It seems like people traditionally do this by editing the .htaccess file (for example here), but I can't seem to get that to work. I also tried adding '/' to the HTTPS plugin URL filters, but this didn't work either. All my attempts to add php code to the actual page just ends up in an infinite redirect.
Looks like the thing that was getting me was the order in htaccess. Everything works now and my file looks like this
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
It was important to put the https rule first, which I hadn't done originally.
This should work:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
This checks to see if https is not on (so if it is off) then redirect the request to https
I've tried implementing a number of suggested solutions to this problem but can't get anything to work.
I am using 2 .htaccess files, one in my root directory which reads as follows:
RewriteEngine on
RewriteBase /
RewriteRule ^(webservice|api) - [L]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://www.domain.com%{REQUEST_URI} [R=301,L]
This redirects all traffic to the main website through https which I need.
However in a subdirectory I want to disable the reroute and force all requests that go to this directory through http. The .htaccess file in /webservice/rest/ reads:
RewriteEngine On
RewriteBase /webservice/rest/
RewriteCond %{HTTPS} on
RewriteRule (.*) http://www.domain.com/webservice/rest/%{REQUEST_URI} [R=301,L]
RewriteRule ^testingPost/?$ testingPost.php [NC]
RewriteRule ^([a-zA-Z0-9\_\-]+)/?(\?([a-zA-Z0-9\_\-\=\?\&]))?$ otherfiledirect.php?method=$1¶ms=$2 [NC]
There are a few redirects taking place, but the 3rd and 4th line in the 2nd htaccess don't seem to be doing anything - can anyone see what I'm doing wrong and how to keep https on the main site but force http on any url below /webservice/rest/ ??
Cheers
The problem was with the ssl config file in the server. Allow Override needed to be set to All under the secure virtual host at port 443. After changing that, the following code in the root htaccess file allowed me to force https across the whole website except a specific folder:
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !/webservice [NC]
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
So any request to http would go to https. However I still needed to explicitly change requests to https on my specified folder to redirect to http, so added the following code after the above:
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} /webservice [NC]
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Bullet proof.
Try this in /webservice/rest/.htaccess and make sure to test in a new browser:
RewriteEngine On
RewriteBase /webservice/rest/
RewriteCond %{HTTPS} on
RewriteRule ^ http://www.domain.com/%{REQUEST_URI} [R=301,L,NE]
RewriteRule ^testingPost/?$ testingPost.php [L,NC]
RewriteRule ^([\w-]+)/?(\?([\w-=?&]))?$ otherfiledirect.php?method=$1¶ms=$2 [L,NC]
I have a problem that only affects google chrome. I have two subdirectories secure.fixnode.ca and storage.fixnode.ca, both of these sudirectories need to use https protocol.
The error I get in Google Chrome is: "Redirect Loop Error, Too Many Redirects"
storage.fixnode.ca works OK in google chrome, but for some reason secure.fixnode.ca does NOT.
Also BOTH subdirectories work great in every other browser (IE, FF, Safari).
below is my .htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^fixnode\.ca$ [NC]
RewriteRule ^.*$ http://www.fixnode.ca%{REQUEST_URI} [R=permanent,L]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(secure|storage)\. [NC]
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
# END OF CHANGE
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^\.]+)/$ $1.php
ErrorDocument 401 /?loc=401error.php
ErrorDocument 404 /?loc=404error.php
Options -Indexes
The line that is giveing me trouble is:
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
it seems that google chrome sees apache https redirects as a redirect error.
does anyone know if I can do this any other way that will work in google chrome and other browsers?
Any help is appreciated
Thanks,
Phillip K
Judging from your situation it seems your https redirect goes into an infinite redirect loop. I've reason to believe the %{HTTPS} variable isn't as stable is it should be (I've seen other people have had problems with this).
Try to change the %{HTTPS} condition from:
RewriteCond %{HTTPS} off
to:
# If not port 443 (https) then this condition should match
RewriteCond %{SERVER_PORT} !^443$
Alernatives are:
RewriteCond %{SERVER_PORT} ^80$
and..
RewriteCond %{REQUEST_SCHEME} ^http$
I am using the following httaccess content, to force rewrite the url's to use https instead of http
RewriteEngine on
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.mydomain.com/$1 [L]
But it's always getting,
The page isn't redirecting properly
Firefox has detected that the server is redirecting the request for this address
in a way that will never complete.
This problem can sometimes be caused by disabling or refusing to accept
cookies.
I've used many other solutions but always getting this...
Try the code below for .htaccess
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
#uncomment the below two line if you need to append www
# RewriteCond %{HTTP_HOST} !^www\. [NC]
# RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]