Google search for my site is missing "www" prefix - .htaccess

I have a problem similar to this, but changing the .htaccess file hasn't solved my problem.
I have addressed this issue by including the following two rules into my .htaccess file. It now correctly redirects any http requests without the www prefix, to the page with it. The problem now is that google is still displaying the site without the prefix. The homepage is showing on google with the www. prefix, but not other pages.
RewriteCond %{HTTP_HOST} ^websitename.com [NC]
RewriteRule ^(.*)$ http://www.websitename.com/$1 [L,R=301]

Use Google Search Console:
Specify a preferred domain: On the Search Console Home page, click the
site you want. Click the gear icon , and then click Site Settings. In
the Preferred domain section, select the option you want.
Set your preferred domain (www or non-www)

Related

Opencart dont redirect not found links

I migrated my e-commerce site oscommerce to open-cart and my old links coming to the open-cart site. whenever old links requested open-cart redirects to the homepage if the pattern is like this .../index.php?manufacturers_id=...
I changed .htacess file to exclude redirect to the homepage by defining these lines
RewriteCond %{REQUEST_URI} manufacturers_id
RewriteRule .* NOT.php
if requested url contains manufacturers_id "it will" redirect to NOT.php instead homepage. But these .htaccess definitions don't work
I also want to cancel 404 pages I prefer to use the server default error page.
How can I make this? Thank you

How to give a subpage it's own domain name?

I have a Joomla site mysite.com.
I want to have the subpage mysite.com/example act like a separate website using a separate domain name anothersite.com.
Can this be achieved using DNS settings on the domain and htaccess?
Hosting sites at cloudaccess.net but want this solution for one-page sites and landing pages without using a whole other hosting account / joomla instance.
Thanks.
If your hosting provider allows you to have "alias" domains, you can point the new domain at the existing code, and detect the hostname using RewriteCond:
Start by configuring the new domain to display all the same content as the existing domain.
In the Apache configuration (probably .htaccess on shared hosting) add a rule which detects requests for the new domain, and "rewrites" them to instead serve your specific page:
RewriteCond %{HTTP_HOST} landingpage.example.com
RewriteRule ^/$ /url/for/my/landing/page
Add an additional rule afterwards so that other URLs on that domain redirect the browser back to the main site
RewriteCond %{HTTP_HOST} landingpage.example.com
RewriteRule ^/([^/].*)$ http://realsite.example.com/$1 [R=permanent,L]
A variation of this would be to map everything on the second domain to a directory (or, rather, a URL prefix) in the first domain, by combining those two rules:
RewriteCond %{HTTP_HOST} subsite.example.com
RewriteRule ^/(.*)$ /url/for/my/subsite/$1 [L]
Note: If Joomla thinks it knows the "correct" URL for the page, it may try to redirect away from your new domain. If so, that is the topic for a new question.
If, on the other hand, you want to use Apache configuration to force users accessing http://realsite.example.com/url/for/my/landing/page to be redirected to http://landingpage.example.com/, you could add something like this:
RewriteRule ^/url/for/my/landing/page$ http://landingpage.example.com/ [L,R=permanent]
Note: Depending on some environment settings I don't fully understand, you may need to change ^/ to just ^ in the patterns above.

Remove Plesk preview domain redirect

Plesk offers you a handy way to preview the site before you switch over the DNS, called Websites Preview.
This is what it does:
customer-site.tld will be available for preview as customer-site.tld.192-0-2-12.your-domain.tld. Here 192-0-2-12 is the site's IP where dots are replaced with dashes
I find this feature very useful, as we use it for proofing websites before they go live, however after the site goes live the customer-site.tld.192-0-2-12.your-domain.tld URL still exists, and is showing up in some Google results!
How can I remove the preview URL for certain sites only, not for all sites on the server?
Alternatively I think I may be able to use a .htaccess rule for this, but I cannot figure out how to do that without a redirect loop.
I found the answer to this with some more searching (I searched for how to redirect domain alias, as that's what this essentially is).
The answer is here: Redirecting all domain aliases to one with htaccess
RewriteEngine On
# If the hostname is NOT www.domain.com
RewriteCond %{HTTP_HOST} !^www\.domain\.com$
# 301 redirect to the same resource on www.domain.com
RewriteRule (.*) http://www.domain.com/$1 [L,R=301]
Use robots.txt file to prevent crawlers from indexing your page. After you have done DNS switching, remove robots.txt file

Get Originally Requested URL for "View Full Site" Link After Mobile Redirect

I've searched thoroughly for a similar topic and couldn't find one. Here's hoping someone can help.
=> THE SET-UP:
I'm using an .htaccess mobile redirect that I found in the wild.
The redirect sends visitors on mobile devices from www.MYSITE.com to m.MYSITE.com (a simple .html "splash page"). On this mobile version is a link for visitors to use to continue to the full site:
Visit Full Version
=> THE PROBLEM:
A user visits www.MYSITE.com/page from a search engine. The user is redirected to the mobile splash page at m.MYSITE.com and they click the "Visit Full Version" link. Instead of being redirected to the full site version of www.MYSITE.com/page, they are sent to www.MYSITE.com.
I need visitors to be able to get back to the originally requested URL (like www.MYSITE.com/page or even www.MYSITE.com/page/post) from the m.MYSITE.com splash page "View Full Version" link.
My .htaccess code is below:
# If you're not already on m.YOUR_DOMAIN_NAME.com,
# and if you're on a mobile device,
# and if you just got here (didn't get here by clicking links on YOUR_DOMAIN_NAME.com),
# and if you're not just looking for pictures
# then go to the mobile site instead
RewriteCond %{HTTP_HOST} !^m\.MYSITE\.com [NC]
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|iphone|ipod|iemobile|webos|googlebot-mobile" [NC]
RewriteCond %{REQUEST_URI} !\.(jpg|png|gif)$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(.*).MYSITE.com/.*$ [NC]
RewriteRule ^(.*)$ http://m.MYSITE.com [L,R=302]
=> THE QUESTION:
What can I work into my .htaccess file and/or mobile index.php to send visitors back to their originally requested URL as the "Visit Full Version" link?
Any help is greatly appreciated!
Thanks,
Brian
Use conditional .htaccess here.
Pass parameter to decide whether you want to see the full site
Visit Full Version
if .htaccess check whether seeFullSite param is set and value is YES. if true, then do not redirect to your mobile site.
Example of conditional .htaccess ::
conditional htaccess?
Conditional .htaccess

Redirect domain

I noticed that Google somehow indexed my site but with incorrect subdomain. Instead of putting a link to www.mydomain.com or mydomain.com it shows ns1.mydomain.com and ns2.mydomain.com, which results in broken images, because I used relative paths.
Now, I don't even have ns1 and ns2 setup as subdomains. I have those in my DNS settings.
So, how do I go about redirecting users to the correct address?
Thanks
OK, I think I was able to fix this by placing this into my .htaccess file
RewriteCond %{HTTP_HOST} ^ns1.mydomain\.com
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=permanent,L]
But even though I fixed it, I am very curious how did Google index those links anyway?

Resources