.htaccess htaccess并可能导致重复内容

.htaccess htaccess并可能导致重复内容,.htaccess,.htaccess,我在一个网站上工作,它的所有页面都在谷歌上建立了索引,但没有一个页面在排名。不久前,该网站被转换为100%https,我怀疑htaccess代码可能会导致某种重复内容问题。以下是我继承的代码: RewriteEngine On RewriteBase / # #Redirect to wwww.example.com #rewritecond %{http_host} ^example.com [nc] #Rewriterule ^(.*)$

我在一个网站上工作,它的所有页面都在谷歌上建立了索引,但没有一个页面在排名。不久前,该网站被转换为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正在产生一些奇怪的结果,例如


我正在尝试清理代码,以便它将所有页面指向url的https版本,例如,不会创建重复内容或任何其他问题。提前感谢所有能够为我指出正确方向的人。

首先,您需要在顶部重定向规则中添加一些
L
标志,这样重写引擎就不会继续执行下面的规则。其次,
RedirectPermanent
是一个不同的模块(mod_别名),它将使mod_rewrite和mod_别名都应用于相同的请求。因此,请改用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规则,不知道这是故意的还是应该是HTTPS:

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