index.php作为laravel网站url中的一个参数


index.php as a parameter in the url of laravel website

我发现任何laravel网站都可以使用index.php作为参数访问。

这是一个大问题,url参数中的index.php会破坏所有图像。看看一个真实的例子来理解我的意思:

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

Googlebot以index.php作为url的参数读取一些url。当有人使用index.php从谷歌搜索访问网站时,这会破坏所有图像。

此外,这是一种糟糕的seo做法,因为会产生重复的内容。

解决这个问题的最佳方法是什么?

这个问题可以通过nginx重写规则来解决。使用以下规则将所有带有index.php参数的URL重定向到original laravel route url

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

此外,我还对robots.txt 进行了以下操作

Disallow: /*index.php*

您的webroot或公共文件夹中是否有随Laravel提供的.htaccess文件?

如果没有,请尝试将其放在公共目录中的.htaccess文件中:

<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>

直接从Laravel GitHub中获取此.htaccess

此外,您可能需要检查是否为您的Web服务器启用了重写mod。

参考如何检查服务器上是否启用了mod_rewrite?

您也可以简单地做到这一点。。。。。。

1.打开apache''conf''httpd.conf并搜索这一行

#LoadModule rewrite_module modules/mod_rewrite.so2.然后删除[#]并保存,然后重新启动apache