So I put these commands in my .htaccess file
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
and something peculiar happened. In my HostGator access logs, I never saw reportage of download success (as in Apache code 200). I seemed to get mainly 301 redirect notifications. That is, people were downloading stuff fine, but I never saw any indication of that in my access logs. Can someone explain to me why that is? I am an Apache novice, so pardon my misunderstanding.
I removed those lines and, yep, all my expected code 200 notifications returned.
Related
I really struggle with .htaccess. I found some possible solutions here but they give me a "Cannot find server" error. I'm using an Apache server (SiteGround).
I have a page (with children) set up in WordPress, and we'd like them to act as a subdomain site while still being part of our WordPress install:
domain.com/new
domain.com/new/children
I'd like these things to happen:
new.domain.com should load the page at domain.com/new (URL should remain new.domain.com - not redirect)
The children should load as new.domain.com/children
entering domain.com/new or domain.com/new/children should redirect to the new subdomain equivalent.
I have tried:
RewriteCond %{REQUEST_URI} ^/new
RewriteRule ^new/(.*)$ http://new.domain.com/$1 [R,L]
Also:
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^new/$ https://new.domain.com/ [R=301,L]
They both redirect /new/ to new.domain.com/ correctly, but the subdomain itself just has a "server not found" error. I tried making an A record pointing the subdomain to the root IP address.. (I have no idea, just a stab in the dark)
Or I'm using the wrong directives?
Not opposed to using WP_Rewrite or something in functions.php if it works better, but I also have no idea about those! I normally make static marketing sites!
I'm looking for help with a chain redirect issue, please.
Desired behaviour: example.com/foo?amp redirects to example.com/bar
Current behaviour: example.com/foo?amp redirects to example.com/foo then redirects to example.com/bar
This is a Wordpress site. Htaccess has the following rule, which doesn't appear to be solving the chain redirect:
RewriteCond %{QUERY_STRING} amp
RewriteRule ^/foo$ /bar [L,R=301]
My htaccess kung foo is quite weak, so I'm fully expecting that I've made a mess there!
Any help appreciated :)
You missed just a tiny detail to get things working:
RewriteEngine on
RewriteCond %{QUERY_STRING} amp
RewriteRule ^foo$ /bar [L,R=301]
The pattern in the rewriting rule is matched against the relative path of the URL (foo, not/foo), when implemented in a distributed configuration file (".htaccess").
It really makes sense to read the documentation of the tools you are using for such details. As typical for OpenSource software the documentation for the apache http server and its module is of excellent quality and comes with great examples.
You want to start with here:
http://httpd.apache.org/docs/current/howto/htaccess.html
https://httpd.apache.org/docs/current/mod/mod_rewrite.html
One could optimize above rule a bit:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^amp$
RewriteRule ^/?foo/?$ /bar [R=301,END]
And you should check whether you can implement such a rule in the actual http server's host configuration instead of using distributed configuration files...
A bit out of my comfort zone, hoping someone can point me in the right direction!
I need to force all http://www.mywebsite.com to go to https://sub.mywebsite.com.
So, I need to force all visitors to the sub-domain, but also the secure https version.
I've tried editing the root htaccess file but I get 'too many redirects' error.
The new site is using a Wordpress child theme in case that makes a difference - when I edited the root htaccess the site appeared unstyled and the 'too many redirects' error related to CSS and JS files.
I'm sure it's something silly and small but any help, much appreciated! :-)
Thanks
Try putting this into the htaccess file above all other existing rules:
RewriteEngine On
# First redirect to the subdomain
RewriteCond %{HTTP_HOST} ^(www\.)?example.com
RewriteRule ^(.*)$ https://sub.example.com%{REQUEST_URI} [L,R=301]
# Then ensure HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://sub.example.com/$1 [L,R=301]
TL;DR: I want to redirect https to http on all pages except for admin/login, where I want the exact opposite to happen. I also want www redirected to bare domain name. (UPDATE: Check Update 3 for the answer)
As is probably clear from the title, I have a Wordpress blog hosted on OpenShift for free. I have a custom domain bought from GoDaddy. I'm using cloudflare so I can have free SSL.
Here's my configuration:
CloudFlare DNS:
CloudFlare Page Rules:
This is what worked best. I actually wanted to have this rule:
*ghostlessmachine.com/* -> https://ghostlessmachine.com/$1
But I ran into even more problems like that, even though it seems to be pretty much what I'm supposed to do according to this CloudFlare article. Actually, initially I wanted to only force SSL in admin pages, but I didn't even know how to attempt that. I thought of using two page rules, like this:
*ghostlessmachine.com/* -> http://ghostlessmachine.com/$2
*ghostlessmachine.com/wp-* -> http://ghostlessmachine.com/$2
But I had no luck.
Here's my OpenShift configuration:
When I write ghostlessmachine.com in my address bar, it correctly takes me to https:.... I have shared a link, however (https://ghost...), and one person has reported not being able to access it. I couldn't reproduce locally.
When I try www.ghost..., I get:
This webpage has a redirect loop
ERR_TOO_MANY_REDIRECTS
Does anybody have any idea what I'm doing wrong? I've lost track of how many different configurations I've tried, but nothing seems to work.
Thanks!
UPDATE
OK, so following the advice in the comment I managed to get the situation a bit better. Still it's counter intuitive for me how the article I initially linked to just didn't get the job done while the other SO question did. So here's what I've changed:
Deleted the www.ghost... alias from OpenShift.
Changed CloudFlare's CNAME record from www -> blabla.rhcloud.com to www -> ghostlessmachine.com
Created this Page Rule: www.ghostlessmachine.com/* -> http://ghostlessmachine.com/$1
Now both ghost... and www.ghost... work and take me to http://ghost.... However, if I type https://ghost..., it also works without redirecting me to simple http. This is a problem.
I tried using this Page Rule instead:
ghostlessmachine.com/ -> http://ghostlessmachine.com/$2
So that I got https://, http://www, www, everything redirected to http://ghost..., but it doesn't work. I can't access my blog anymore and whatever address I try I get ERR_TOO_MANY_REDIRECTS.
UPDATE 2
Here's my full setup after all suggestions:
htaccess:
wp-config.php:
CloufFlare:
Result:
https -> http on non-admin/login pages: WORKING ✓
Trying to access admin/login pages: ERR_TOO_MANY_REDIRECTS
Update 3
This did the trick:
I still don't understand why this works and the rest doesn't though. This was basically a series of rather blind trial and error with some input from Allen here and Simon in the CloudFlare support page. In any case, all my requirements are respected now, thanks!
make sure following in your wp-config.php file:
define('FORCE_SSL_ADMIN', true);
define('FORCE_SSL_LOGIN', true);
look over here: Force non-WWW but force https across all of wordpress & the entire domain
for redirect everything else to non-https, you can add following into your root .htaccess file, before the wordpress rewrite:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} =on
RewriteCond %{REQUEST_URI} !^/wp-admin.*
RewriteCond %{REQUEST_URI} !^/wp-login.*
RewriteCond %{HTTP_REFERER} !^https://.*
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Update:
CloudFlare's Page rule has following "Page rule priority is determined by their position in the list. If multiple rules match a URL, rules at the top take higher priority. "
let's see what happens before:
request to https://www.ghostlessmachine.com/wp-admin hit the first
rule, match found, then it goes to
http://www.ghostlessmachine.com/wp-admin!
now here comes http://www.ghostlessmachine.com/wp-admin, first rule,
no rewrite, goes down to 3rd rule, oops, it needs goto
https://www.ghostlessmachine.com/wp-admin!
this is how the loop comes
My problem is on a GoDaddy hosted Wordpress installation. I decided to move the site just a few days after adding SSL, and I left the certificate behind, I no longer want it. Many users are still seeing my site as https://example.com because Google indexed this, or because the site is in their cache. This is a big problem, because browsers throw up untrusted certificate warnings, and users don't continue on to the site.
I've been trying to solve this problem by:
Using Google Webmaster Tools and asking Google to re-crawl/re-index my URLs.
Trying to write a 301 redirect into my htaccess file, which would redirect from https to http.
My 301 redirects have not worked yet. I have read several articles and tried these code snippets:
RewriteCond %{SERVER_PORT} ^443$
RewriteRule (.*) http://example.com/$1 [R=301,L]
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule .* http://%{HTTP_HOST}%{REQUEST_URI}
I'm beginning to doubt that this will work. Does anyone know if it is possible?
In the end, only time healed this wound. Fortunately Google un-indexed my HTTPS address pretty quickly.