htaccess并可能导致重复内容

时间:2013-12-18 00:41:15

标签: .htaccess

我正在开发一个网站,其所有网页都已在Google中编入索引,但这些网页都没有排名。该网站暂时转移到100%https,我怀疑由于htaccess代码可能会出现某种重复的内容问题。这是我继承的代码:

RewriteEngine On        
RewriteBase /       
#
#Redirect to wwww.example.com       
#rewritecond %{http_host} ^example.com [nc]     
#Rewriterule ^(.*)$ http://www.example.com/$1 [r=301,nc]        
#       
#Remove the index.php after domain.com/index.phpl
RewriteCond %{HTTPS} !=on   
RewriteRule ^/?(.*) https://www.example.com/$1 [R=301,nc]   
rewritecond %{THE_REQUEST} ^[c-t]{3,9}\ /index\.php\ HTTP/ [NC]     
Rewriterule ^(.*)index\.php /$1 [R=301]     

ErrorDocument 404 /404Error.php

#Begin Redirects

#FOR DIRECTORY REDIRECT
RewriteCond %{QUERY_STRING} &?p=11&?
RewriteRule ^exampleblog/$ http://www.example.com/new-york.php? [R=301,L]

RedirectPermanent /about.html https://www.example.com/about.php
RedirectPermanent /example-video.php https://www.example.com/
RedirectPermanent /brooklyn.php https://www.example.com/kings-county.php

这是一个静态网站,而htaccess正在产生一些奇怪的结果,例如https://www.example.com/about.php/index.php

我正在尝试清除代码,以便将所有网页定向到网址的https版本,例如https://www.example.com/,而不是创建重复内容或任何其他问题。提前感谢任何能够指出我正确方向的人。

1 个答案:

答案 0 :(得分:0)

首先,您需要在重定向规则中添加一些L标记,以便重写引擎不会继续执行进一步的规则。其次,RedirectPermanent是一个不同的模块(mod_alias),因此mod_rewrite和mod_alias都将应用于同一个请求。所以请改用mod_rewrite:

RewriteEngine On        
RewriteBase /       

#Remove the index.php after domain.com/index.phpl
RewriteCond %{HTTPS} !=on   
RewriteRule ^/?(.*) https://www.example.com/$1 [R=301,nc,L]   
rewritecond %{THE_REQUEST} ^[c-t]{3,9}\ /index\.php\ HTTP/ [NC]     
Rewriterule ^(.*)index\.php /$1 [R=301,L]     

ErrorDocument 404 /404Error.php

#Begin Redirects

#FOR DIRECTORY REDIRECT
RewriteCond %{QUERY_STRING} &?p=11&?
RewriteRule ^exampleblog/$ http://www.example.com/new-york.php? [R=301,L]

RewriteRule ^about.html$ https://www.example.com/about.php [L,R=301]
RewriteRule ^example-video.php$ https://www.example.com/ [L,R=301]
RewriteRule ^brooklyn.php$ https://www.example.com/kings-county.php [L,R=301]

你还有一个非SSL规则,dunno,如果这是故意的,或者应该是HTTPS:

#FOR DIRECTORY REDIRECT
RewriteCond %{QUERY_STRING} &?p=11&?
RewriteRule ^exampleblog/$ http://www.example.com/new-york.php? [R=301,L]