If I search under "site:www.example.com" I don't see any results, but if I search "site:example.com" I do. Why? - subdomain

In Search Console I have it as "don't set preferred domain."
What could be causing this?

You should check your HTTP headers. If www.example.com gives 404 not found error, Google will not index that subdomain.
To make sure you have both version idexed and also avoiding duplication of content, try to add this to your .htaccess:
RewriteEngine on
# Redirect non-www to wwww
RewriteCond %{HTTP_HOST} !^www\.yourdomain\.org [NC]
RewriteRule ^(.*)$ http://www.yourdomain.org/$1 [R=301,L]

Related

Redirect from one website to another and keep directory

The blog section of a website moved from a subdomain to a directory of the main domain. I need to redirect all users visiting blog.site.com to site.com/blog/ and the directory someone enters should be kept when forwarding, e.g. blog.site.com/post/welcome should point to site.com/blog/post/welcome
I treid adding this to my .htaccess file which I placed in the subdomain's directory via FTP:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^blog.herderzeitung.de$ [OR]
RewriteCond %{HTTP_HOST} ^www.blog.herderzeitung.de$
RewriteRule (.*)$ https://herderzeitung.de/blog/$1 [R=301,L]
However, this doesn't seem to be working. I was also wondering, what the most SEO friendly way is to achieve this (the site permanently moved to another domain).
Thanks in advance!
Try
RewriteEngine On
RewriteCond %{HTTP_HOST} ^blog\.herderzeitung\.de$ [OR]
RewriteCond %{HTTP_HOST} ^www\.blog\.herderzeitung\.de$
RewriteRule ^/?(.*)$ https://herderzeitung.de/blog/$1 [R=302,L]
I've escaped the dots, and anchored&normalized the pattern. Also switched it to temporary redirects (302); once you know it works, then change it to 301 again for SEO reasons.
And yes, as far as i know 301s are the best method for retaining your search rankings and the like.
This seems to work:
RewriteEngine On
RewriteCond %{REQUEST_URI} (.*)
RewriteRule ^(.*)$ https://herderzeitung.de/blog/$1 [L,R=301]
Thank you everyone!

.htaccess http to https not working

despite searching for previous answers, I couldn't see one which addresses my issue, so hope someone can help?
I recently redirected an old html company site to a new wordpress site with .htaccess rules (obvs different domain)
however, shortly afterwards I updated the new domain with an ssl cert. The old site was just a regular http:
I changed the .htaccess rules for the https: but obvs I have done it incorrectly as the redirect does not work.
this is what I am using.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^old-domain.co.uk$ [OR]
RewriteCond %{HTTP_HOST} =www.old-domain.co.uk
RewriteRule (.*) https://newdomain.com$1 [R=302,L]
</IfModule>
what do I need to change to have it redirect correctly?
thanks for your assistance.
I prefer this variant for redirecting from http to https
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Also there are a lot of plugins for wordpress that help with that. They also help with redirecting all request to resources (images etc) to https
It works for me.
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://newdomain.com/$1 [L,R=301]

htaccess why is site redirecting to //

In my htaccess I am redirecting all non https to https.
It works, but its also adding in an extra '/', so the url is
'https: //www.[MY SITE URL].co.uk//'
Why is this? To be honest, I don't really know what all this in my htaccess is doing, its copied from googling answers to 'redirect all requests to https'
My htaccess:
Options -MultiViews
RewriteEngine On # Turn on the rewriting engine
RewriteBase /
#RewriteCond %{HTTP_HOST} ^(www\.)?jobooz\.com [NC]
#RewriteRule ^(.*)$ https://www.jobooz.co.uk/$1 [R=301,L,NC]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI}/$1 [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI}/$1
RewriteRule ^/?$ /php/index.php [NC,L] # Home page
I've also noticed any deeper urls like '/search-jobs/jobs-near-me' that I add to the url then get duplicated too, to '/search-jobs/jobs-near-me/search-jobs/jobs-near-me' when redirected to https.
All urls work fine if I go directly to the https version.
Any help appreciated, thanks.
The following rewrite rule has a problem:
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI}/$1 [R=301,L]
The gist of why you are seeing repeated fragments in the rewritten URL is that (.*) matches everything, and that already includes the host and URI. Instead, you can try redirecting any incoming request on port 80 to HTTPS.
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

.htaccess Redirect all users to subfolder EXCEPT for IP

I've tried countless combinations from forums, answers here on Stack Overflow, and blogs. I can't get this to work right.
I'd like to redirect all users to a subdirectory - "/const" - except for an IP that I deem worthy.
This is what I'm using so far:
RewriteEngine on
RewriteCond %{REMOTE_ADDR} !^91\.143\.253\.211
RewriteCond %{REQUEST_URI} !^/const/ [NC]
RewriteRule ^(.*)$ http://website.com/const/$1 [R=302,L]
And it redirects to the subfolder correctly, but it still redirects me, which is bad.
Little help?
You can use a Skip flag [s]. Here is an example with multiple IPs.
RewriteEngine on
RewriteBase /
RewriteCond %{REMOTE_ADDR} ^91\.143\.253\.211$ [OR]
RewriteCond %{REMOTE_ADDR} ^8\.8\.8\.8$
RewriteRule .? - [S=1]
RewriteCond %{REQUEST_URI} !^const [NC]
RewriteRule ^(.*)$ /const/$1 [R=302,L]
Note
In the example before I had %{REQUEST_FILENAME}. This typically only works on server config files where the path to the filename itself is visible to the redirection script. Here I've changed it to %{REQUEST_URI} the part of the request that the browser can actually access.
The rule that you have is correct. When I add those to a blank htaccess file, I get redirected to http://website.com/const/ as expected unless I change the first condition to my actual IP. Some things you should check:
Make sure you've flushed your browser's cache. Although 302 redirects shouldn't be cached in such a way, better to flush it just in case.
Make sure you are actually making a request from the expected IP (i.e. ^91\.143\.253\.211$). You can test this by adding this rule to the top of your htaccess file:
RewriteRule ^foo$ http://foo.bar/IP/%{REMOTE_ADDR} [L,R]
And if you go to http://website.com/foo you should get redirected to a non-existing site but with your IP in the URL. If that IP doesn't match 91.143.253.211 then you need to change your condition to match the right IP.

How to force http- NOT https using htaccess

I have ONE directory for my entire domain that I want to force https, which is "/docs". In the /docs folder, I have the following htaccess file:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
This is forcing https to everything in the /docs directory, which is what I want it to do. The problem I am having is trying to force REMOVE https back to http for all other areas of my site. In the root folder of the site (which is running wordpress), I have the following htaccess file:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^/docs/?.*$
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L]
Unfortunately, this is not working. I can still access other areas of my site over https.
What do I need to change to get this to work correctly?
Since the accepted answer doesn't actually answer the question, I figured I'd post my solution to this. Add this to your .htaccess file to force HTTP instead of HTTPS:
# BEGIN Force HTTP
RewriteEngine On
RewriteCond %{SERVER_PORT} 443
RewriteRule ^(.*)$ http://yourdomain.com/$1 [R=301,L]
# END Force HTTP
Try the Force non-SSL plugin for wordpress.
The "WordPress Force HTTP" plugin was the only thing that worked for me. It changes https to http for not just the front page like most of the answers out there, but also changes https to http for all sub-directories in your website.
https://en-au.wordpress.org/plugins/wp-force-http/
Why do you need to revert back to http? If you have the proper SSL certificates you might as well keep your access secure. Unless you are concerned about the load on your system.
I know this is not answering the question, but I want to emphasize that the question is asking on how to do a bad practice, which shouldn't be done in the first place.