php - ci : google indexing address with index. php 但站点中没有与 index.php 的链接

标签 php .htaccess codeigniter seo codeigniter-url

我有一个由 codeigniter 编写的网站,我已经通过 htaccess 从地址中删除了 index.php

RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA] 

我的 base_url() 也将输出没有 index.php 的站点域 所以我在网站上的所有链接都没有 index.php 即:

www.site.com/news/add
www.site.com/faq
www.site.com/offers/archive 

问题来了: 我注意到谷歌也用索引 php 为我网站上的许多地址编制了索引 例如,我的网站中有这个地址:

www.site.com/offer/map

但谷歌只有

www.shadyab.com/index.php/offer/map

索引不是第一个!

谷歌从哪里获得这些链接?

这是我的 routes.php

$route['default_controller'] = 'index';
$route['404_override'] = '';
$route['cp'] = 'cp/admin';
$route['404.php']      = "404.php";
$route["page/(:any)"]   = "page/title/$1";
$route["offers/(:any)"] = "offer/get/$1";
$route["category/(:any)"] = "offer/open/0/$1";
$route["rss"] = "news/rssOffers";
$route['sitemap\.xml'] = "offer/sitemap";

我的访问权限

 AddType application/x-httpd-php53 php53 php


<IfModule mod_rewrite.c>

RewriteEngine on



#forcing www
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# redirecting addresses with index.php to address without it
# (i've added this just yesterday it's not related to my problem )
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php(/[^\s\?]+)? [NC]
RewriteRule ^ %1/ [L,R]

#adding inddex.php internally 
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA] 



</IfModule>


order allow,deny
allow from all

最佳答案

您的网站正在重定向 index.php 但它发送的是 302 重定向,即 temporary redirect .你想要做的是使用 301 Moved Permanently .

使用 301,google 将收到旧 URL 不再有效的通知,并使用新 url 更新其索引。

Change 302

将此规则添加到您的 .htaccess

RewriteRule ^index.php/(.*)$/$1 [R=301,L]

关于php - ci : google indexing address with index. php 但站点中没有与 index.php 的链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24961880/

相关文章:

javascript - 使用 JavaScript 或 PHP 动态生成 CSS 网格

php - PHP中简单数字的float到int改变值

.htaccess - Joomla 组件的 htaccess 干净 url

.htaccess - 重定向旧静态移动网站的最佳实践

html - 我应该在标准 HTML 上使用表单助手吗?

php - 使用 foreach 将元素数组放在正确的标题下

javascript - 将数据从 json 传递和使用到 javascript

php - 表格 : Make Input Mask

apache - 将 get-parameter 添加到 .htaccess 中的 rewrite_rule 不起作用

php - Phil Sturgeon 的主题模板库