skip to Main Content

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.cyprusalive.com/main-thing/sightseeing
http://www.cyprusalive.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?

4

Answers


  1. Chosen as BEST ANSWER

    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*
    

  2. 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?

    Login or Signup to reply.
  3. Since you’re using NGINX, check this

    Login or Signup to reply.
  4. Also you can do this simply……

    1.Open apacheconfhttpd.conf and search for this line

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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search