Why does google does not put "http://" in my website name? - .htaccess

I always set my domains to avoid www and use http://, however google never indexes http://, which means in the google results my website always shows up as mywebsite.com only.
# activate URL rewriting
RewriteEngine on
# Remove www
RewriteCond %{HTTP_HOST} ^www.mywebsite.com$ [NC]
RewriteRule ^(.*)$ http://mywebsite.com/$1 [R=301,L]
# do not rewrite links to the documentation, assets and public files
RewriteCond $1 !^(index\.php|public|images|robots\.txt)
# do not rewrite for php files in the document root, robots.txt or the maintenance page
RewriteCond $1 !^([^\..]+\.php|robots\.txt|sitemap\.xml)
# but rewrite everything else
RewriteRule ^(.*)$ index.php?/$1 [L]
Has the issue anything to do with my .htaccess file?

You can't force google to show http:// , google always remove it if url starts with http:// he will keep it if url starts with https://
You can control www with your htaccess file, but not http:// , and purpose of that http://mywebsite.com/$1 is not to tell him to show http:// , you must specify protocol otherwise he will act like you specified local address.
If you check urls in google results you can confirm this, google will show protocol part just if it's not http

Related

Redirect all subdomains and subdirectories to index page using .htaccess

I have a Detroit iOS & Android Mobile App Development website that only has one web page : index.html.
The source code of the site is here.
Instead of showing a 404 error page, I want to redirect the user to thefirstprototype.com if they try to go anywhere else or try to put anything after.
For eg:
mail.thefirstprototype.com takes the user to just thefirstprototype.com
thefirstprototype.com/mail takes the user to just thefirstprototype.com
I know it's possible to do it using a .htaccess in the root folder, but I am just not sure how. There are a lot of tutorials showing how to do it between different domains, but nothing to my specific case. How do I do it?
Thanks
Edit1: Please note that I am not using any CMS like Wordpress. I am just plain FTP to push a static HTML, CSS, JS webpage to the hosting server
Try the following:
DirectoryIndex index.html
RewriteEngine On
# Redirect non-canonical hostnames (eg. mail)
RewriteCond %{HTTP_HOST} !^example\.com$
RewriteRule ^ http://example.com/ [R=302,L]
# Redirect 404 to root
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . / [R=302,L]
However, whether this catches requests for the mail. subdomain will depend on whether that subdomain points to the same place as your main domain. (For cPanel shared hosting, that is not necessarily the case.)
Change the 302 (temporary) redirect to 301 only once you have tested that this works OK - to avoid potential caching issues associated with 301 (permanent) redirects.
As an added bonus, you could redirect any direct requests for index.html back to the root. For example, add the following between the above two rule blocks:
# Remove "index.html" if requested directly
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^index\.html$ / [R=302,L]
The condition that checks against the REDIRECT_STATUS environment variable is to ensure we don't get a redirect-loop since mod_dir internally rewrites the request to index.html.

Rewrite and Redirect with htaccess

A client has asked us to replicate all the content from an old domain (bcsbd.com) to their main domain (ywcacam.org), and also create redirects so the old URLs are still functional. Unfortunately, the URLs aren't exact matches, e.g., [olddomain]/about has become [newdomain]/about_soo_bahk_do. There are less than 10 specific URLs to handle, which we initially did successfully using Redirect statements in the old domain's htaccess file:
# redirect specific pages to page on new domain
Redirect /about http://www.ywcacam.org/about_soo_bahk_do
We also need a catch-all, so that any other requests go to a specific URL on the new domain, e.g., www.bcsbd.com/somefile becomes www.ywcacam.org/soo_bahk_do. We handled this using Rewrite statements:
# catch-all for any requests not specified above
RewriteCond %{HTTP_HOST} ^(bcsbd.com|www.bcsbd.com) [NC]
RewriteRule ^(.*)$ http://www.ywcacam.org/soo_bahk_do [L]
Quick research showed the Rewrite directives (using mod_rewrite) would always be processed before the Redirect directives (using mod_alias). So we replaced the Redirects with Rewrites:
Options +FollowSymlinks
RewriteEngine On
RewriteRule /about http://www.ywcacam.org/about_soo_bahk_do [L]
RewriteRule /programs http://www.ywcacam.org/programs_soo_bahk_do [L]
...
# catch-all for any requests not specified above
RewriteCond %{HTTP_HOST} ^(bcsbd.com|www.bcsbd.com) [NC]
RewriteRule ^(.*)$ http://www.ywcacam.org/soo_bahk_do [L]
The problem is that just the catch-all is working - the new Rewrite rules are being ignored. What are we doing wrong in those statements?
Thanks in advance for the help!

Exclude a substring in htaccess RewriteRule redirect

I manage an old site with multiple domain with the same name,
google has indexed some old url with the language structure
http://www.example.com/eng/whatever
and
http://www.example.it/eng/whatever
and now I don't use this structure anymore, but I want to do a redirect to my new structure
http://www.example.it/en/whatever
so everything after the /eng/ must be appended to the new structure, excluded the /eng/ substring.
But it doesn't work, I have a redirect to
http://www.example.it/en/eng/whatever
which is wrong! I did not want /eng in the redirect url
In my .htaccess I have this
#this will redirect the url with /eng/whatever to www.example.it/en/whatever, regardless from the top level domain
RewriteRule ^eng\/(.*)$ http://www.example.it/en/$1 [R=301,L]
#redirect example.com on www.example.it/en/
RewriteCond %{HTTP_HOST} ^([^.:]+\.)*example\.(com|pt)?(:[0-9]*)?$ [NC]
RewriteRule ^(.*)$ http://www.example.it/en/$1 [R=301,L]
Try replacing all of that with just this:
RewriteRule ^eng/(.*) en/$1 [R,L,NE,DPI]
If it works, you can change the R to R=301
Warning
To test this, you must use a new browser. This is because browsers cache 301 redirects, so your current browser will keep redirecting to the old (wrong page) without even talking to your server and hitting the new .htaccess—unless you clear the browser cache.

Redirect conflicting and not redirecting the correct URL

Need your guidance. i am stuck with permanent redirection via .htaccess in WordPress. I Went through many post on SF but were not up to mark.
Scenario :
i have 2 domains
both domains host same content but on different URL like; old-domain/apple = new-domain/apl
Requisite :
every URL on Old-domain.com should be redirected to New-domain.Net; as i wish means, i will decide which URL from previous domain should redirect to which url on new domain. This should no way be automatically done. There may be chances that i can point two or more URL of old domain to a particular URL on new-domain.
if a particular page or URL etc whatever it may be, is not found on old-domain then it should be redirected to New-domain.
there are few URL that doesn't exist on old-domain any more. with SEO point of view, i would like to redirect them as well on new-domain.
4.
This is what i got closest to doing what i wish.
# 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]
**redirect 301 /apple http://newdomain.com/apl
redirect 301 /colour http://newdomain.com/color**
</IfModule>
# END WordPress
But this set of codes does not work proper with my blog. instead it start to redirect old-domain/wp-admin/edit/php automatically to new-domain/wp-admin/edit/php
Looking for :
i am looking for perfect codes that can help me doing this. just do a demonstration on how to proceed with some fictitious domain name n url, so that i can understand and do my domains.
Thanks

Mod Rewrite redirect URL with query string to pretty url

I successfully changed my URLs from ugly ones with several parameters in the querystring to clean looking ones with the help of mod rewrite. However, there are many url's for my site. Rather than go back and edit the href attribute on each and every one of my anchor tags, I tried to write a redirect function in the .htaccess file that automatically redirects the old url to the new one.
In my .htaccess file, I have the following:
RewriteEngine On
Redirect teams.php?league=$1&team=$2&year=$3&tab=$4 teams/(.*)/(.*)/(.*)/(.*)
RewriteCond %{REQUEST_URI} !^(css|js|img)/
RewriteRule ^teams/([^/]*)/([^/]*)/([^/]*)/([^/]*)$ teams.php?league=$1&team=$2&year=$3&tab=$4 [L]
No luck though... any thoughts?
Thanks
You need to do a check that the old URL with the php in it is actually being requested by matching against %{THE_REQUEST}, otherwise it'll redirect loop forever (e.g. user goes to team.php, serve redirects to teams, browser requests teams, server rewrites as teams.php, server sees "teams.php" and redirects to teams, browser requests teams, server rewrites as teams.php, etc. etc.)
RewriteEngine On
# redirect when the user actually requests for teams.php
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /teams\.php\?league=([^&]+)&team=([^&]+)&year=([^&]+)&tab=([^\ ]+)
RewriteRule ^teams\.php$ /teams/%1/%2/%3/%4? [R=301,L]
# internally rewrite any /teams/ URI
RewriteCond %{REQUEST_URI} !^(css|js|img)/
RewriteRule ^teams/([^/]*)/([^/]*)/([^/]*)/([^/]*)$ teams.php?league=$1&team=$2&year=$3&tab=$4 [L]

Resources