Google Maps Embedded API - Won't work without WWW in URL

1.1k Views Asked by At

I am trying to use the Google Maps Embedded API. I have used this for years on a page we post every so often. This year it wasn't working so I obtained a new key and updated the HTML on the webpage. It now works if I put "www" in front of the page's URL but not if I use the domain name only. Same page, just adding www allows it work. Unfortunately, many of our users and documents refer to our website without the www.

I figured it might be the Google API key restriction "referrer". We use a hosted service, so I am using the "HTTP referrers (web sites)". I have tried it with both the restriction turn off (and waiting 10 minutes) and with all of the following in the HTTP referrers list (our domain though and again waiting 10 minutes):

*.example.com/*
*example.com*
*example.com/*

In both cases, it only works with www.example.com/page.html and not example.com/page.html

Any ideas?

1

There are 1 best solutions below

0
betrice mpalanzi On

If you want to redirect all non-www requests to your site to the www version, all you need to do is add the following code to your .htaccess file:

RewriteEngine On RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

This will redirect any requests tohttp://my-domain.com to http://www.my-domain.com.

There are several benefits from doing that:

  • It will avoid duplicate content in Google

  • It will avoid the possibility of split page rank and/or split link popularity (inbound links).

  • It's nicer, and more consistent.