4

I discovered that any laravel website is accessible with index.php as a parameter.

This is a big problem, index.php in url parameter breaks all images. Look at a real example to understand what I mean:

http://www.example.com/main-thing/sightseeing
http://www.example.com/index.php/main-thing/sightseeing

Googlebot read some urls with index.php as a parameter of url. This has effect to breaks all images when someone get access to the website from google search with index.php.

Also, this is a bad seo practice because produce duplicate content.

What is the best way to fix that?

miken32
  • 42,008
  • 16
  • 111
  • 154
Panagiotis Koursaris
  • 3,794
  • 4
  • 23
  • 46
  • 1
    Isn't this a .htaccess problem? I use CodeIgniter (Same mechanism). WHen i visit it with index.php in the url then everything is still working fina as all the links point to URL's without the index.html. I think there may be something wrong with your configuration too. I have no experience or knowledge on Laravel tough. – Fjarlaegur Aug 04 '16 at 07:08
  • This is a .htaccess problem - to be fair, it seems the default .htaccess that ships with laravel allows this – Chris Aug 04 '16 at 07:08
  • I will use `Disallow: /*index.php*` in the `robots.txt` to fix the problem with google. Is there a better way? – Panagiotis Koursaris Aug 04 '16 at 07:25

3 Answers3

4

The problem could be fixed with nginx rewrite rules. Using the bellow rule redirect all urls with index.php parameter to the original laravel route url

location /index.php {
      rewrite ^/index.php(.*)$ http://$server_name$1;
}

Also I've put the follow to the robots.txt

Disallow: /*index.php*
Panagiotis Koursaris
  • 3,794
  • 4
  • 23
  • 46
0

Do you have the .htaccess file provided with Laravel in your webroot or public folder?

If not, try putting this in a .htaccess file in your public directory:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

Directly taken this .htaccess from Laravel GitHub.

Also, you might need to check if the rewrite mod is enabled for your webserver.

Reference How to check whether mod_rewrite is enable on server?

Community
  • 1
  • 1
Fjarlaegur
  • 1,395
  • 1
  • 14
  • 33
-1

Also you can do this simply......

1.Open apache\conf\httpd.conf and search for this line

#LoadModule rewrite_module modules/mod_rewrite.so 2.then remove [#] and save,then restart apache

tanvirjahan
  • 164
  • 1
  • 1
  • 8