【问题标题】:URL Re Writing issue double http issueURL重写问题双http问题
【发布时间】:2014-10-31 19:41:30
【问题描述】:

我的网址有问题,例如谷歌抓取了双 http

http://example.com/example.com/c-title-id.html

以及所有类似的相互链接的页面

请任何人帮助我用 .htacess 重定向所有带有 301 的 url

我的 htacess 代码是

RewriteEngine on

RewriteCond %{HTTP_HOST} ^www\.website\.com [NC]
RewriteRule ^(.*)$ http://website.com/$1 [L,R=301]

RewriteRule category-([0-9]+)-(.*)-([0-9]+)\.html$ category.php?cid=$1&name=$2&page=$3.php [L]
RewriteRule search-(.*)-([0-9]+)\.html$ search.php?term=$1&page=$2.php [L]
RewriteRule all-covers-([0-9]+)\.html$ all-covers.php?page=$1.php [L]
RewriteRule index-([0-9]+)\.html$ index.php?page=$1.php [L]
RewriteRule featured-covers-([0-9]+)\.html$ featured-covers.php?page=$1.php [L]
RewriteRule top-downloaded-([0-9]+)\.html$ top-downloaded.php?page=$1.php [L]
RewriteRule c-([0-9]+)(.*)\.html$ cover.php?id=$1&name=$2.php [L]
RewriteRule sitemap.xml$ sitemap.php [L]
RewriteRule sitemap1.xml$ sitemap1.php [L]
RewriteRule rss.xml$ rss.php [L]
RewriteRule ^(.*)\.html$ $1.php [L]

ErrorDocument 404 /404.html

我想自动重定向所有这些。

【问题讨论】:

标签: .htaccess mod-rewrite redirect url-rewriting http-status-code-301


【解决方案1】:

应该像在规则的顶部一样简单:

RewriteEngine on

RewriteCond %{HTTP_HOST} ^www\.website\.com [NC]
RewriteRule ^(.*)$ http://website.com/$1 [L,R=301]

RewriteRule example\.com/(.*)$ /$1 [R=301,L]

#... rest of your rules...

【讨论】:

  • 但现在它重定向到 404
  • @user2998120 你是否在上面写着#... rest of your rules...的代码下方附加了旧规则?
  • 是的,我也从标题状态检查器中检查过,如果我在此处输入我的网址是否保存
  • example.com/c-title-id.html 没有上述规则是否有效,或者它会将您重定向到example.com/example.com/c-title-id.html
  • 顺便说一句,我忘了提到这一点,但您需要清除缓存并最好使用不同的浏览器来测试 URL 是否正常工作,因为它是 301 重定向,所以您可以从您以前的网址缓存
猜你喜欢
  • 2012-04-18
  • 2011-03-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多