我有一个由 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 更新其索引。
将此规则添加到您的 .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/