索引覆盖率 - Index.php的重定向错误

时间:2018-03-05 17:48:51

标签: apache .htaccess redirect mod-rewrite

我认为两年前我解决了这个问题,但现在几周以来我受到谷歌搜索控制台的骚扰,“索引覆盖率”指的是我主页的/index.php(我的网站的所有变体都列出了在Search Console中,我在头部有一个规范的URL。另外,如果我打电话给我www.xxx./index.php,它说“页面不起作用 - 重定向太多”。

现在我知道这不是一个直接的编程问题,但是因为它涉及htaccess,这是某种方式的红色和黑色艺术而且只是伏都教,我无法让我的代码正常工作/我的网站可以正确访问重定向。

我的.htaccess解决了以下问题。我已经尝试过切换和删除部分,但它像一个鲁莽的妖精一样坚持:

// This should redirect to http with www

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

// This should redirect index.php requests - to be redirected to https://www.

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\/index\.php\ HTTP/
RewriteRule ^index\.php$ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 
// Redirect from capital Index.php to index.php 
RewriteRule ^Index\.php$ /index.php [R=301,L]

// This redirects from /html and /index requests combined with .php to the https:// version
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.(html?|php)\ HTTP/
RewriteRule ^index\.(html?|php)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteRule ^index\$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

// I'm not sure anymore...
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*[^/])$ /$1/ [L,R]

编辑:我觉得问题是 - 就像我的浏览器和搜索控制台所说的那样 - 发生了太多的重定向(到www.xxx.de/index.php)。所以我尝试了不同的.htaccess部分并删除了一些以最小化重定向,这现在似乎不起作用。 我自己组装零件(不是通过框架),我猜这解释了......

编辑2:在我逐行删除并测试效果后,影响/index.php的唯一部分与预期的RewriteRule ^index\.(html?|php)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]一样,但随后是网站也可以在/index.php

下访问

2 个答案:

答案 0 :(得分:1)

如何替换

RewriteRule ^index\.php$ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 

RewriteRule ^index\.php$ https://www.%{HTTP_HOST}/ [R=301,L]

基本上你想要的是将引用/index.php的用户重定向到/

答案 1 :(得分:0)

我替换了

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\/index\.php\ HTTP/
RewriteRule ^index\.php$ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteRule ^Index\.php$ /index.php [R=301,L]

RewriteCond %{QUERY_STRING} ^$
RewriteCond %{THE_REQUEST} /index\.php
RewriteRule ^index\.php https://www.%{HTTP_HOST}/ [R=301,L]
RewriteRule ^Index\.php$ /index.php [R=301,L]

现在/index.php被正确地重定向到我的www.xxx.net/而没有任何循环。