Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Urls indexed in Google with index.php, Laravel configured to not use it in paths

I deployed recently an little website made with latest Laravel 4. All works well, url rewriting included.

But I noticed that Google indexed a few urls with the index.php in the path. As you know, this can provoke a duplicate content problem.

I triple checked, and there's absolutely no way to access an url with index.php when you browse the website. So I wonder how to prevent the framework to load the urls with index.php, or at least a trick to redirect automatically to the correct url without the index.php.

In the original htaccess, I only added this to force the www in url:

RewriteCond %{HTTP_HOST} ^domain\.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/ [L,R=301] 

I don't think it's the cause of this problem, but I mention it, just in case.

Thanks.

like image 615
Tanyio Avatar asked Jun 20 '13 19:06

Tanyio


People also ask

How does the route Helper Work in Laravel?

The route helper will automatically extract the model's route key: Laravel allows you to easily create "signed" URLs to named routes. These URLs have a "signature" hash appended to the query string which allows Laravel to verify that the URL has not been modified since it was created.

What is a signed url in Laravel?

Laravel allows you to easily create "signed" URLs to named routes. These URLs have a "signature" hash appended to the query string which allows Laravel to verify that the URL has not been modified since it was created. Signed URLs are especially useful for routes that are publicly accessible yet need a layer of protection against URL manipulation.

How to stop Google from indexing a specific route or page?

In short, you might tell Google a specific route or page has "no restrictions for indexing or serving" by setting the X-Robots-Tag HTTP header to all or, on the contrary, tell it to stop indexing (or saving cached versions of a page) with the noindex value. In Laravel, the guys at Spatie made it really easy.

What indexing API does Google use for job posting?

As mentioned by John Mueller, Webmaster Trends Analyst at Google, you can only use the Indexing API for Job posting & live stream structured pages. The package we use is called Laravel Google Indexing, a simple package that uses the Google PHP Client for making API requests.


2 Answers

This is what worked for me, helping me removine Laravel's index.php from the url:

RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
like image 97
jOpacic Avatar answered Sep 21 '22 18:09

jOpacic


Google saves 404 pages, use Google Webmastertools to remove from their cache.

The Rule is wrong I think.

RewriteEngine on
RewriteRule ^/(.*)$ /index.php?$1
like image 44
Daniel W. Avatar answered Sep 17 '22 18:09

Daniel W.