【问题标题】:Should I place a redirect on a url that is rewritten in htaccess?我应该在用 htaccess 重写的 url 上放置重定向吗?
【发布时间】:2015-04-04 13:14:02
【问题描述】:

例如

RewriteEngine On
RewriteRule    ^tour/?$    tour-info.php    [NC,L] 

www.site.com/tour/ 将查看 www.site.com/tour-info.php 内部

我的问题是:将 www.site.com/tour-info.php 保留为可寻址的 url 是不好的 SEO 做法,还是应该在其上放置重定向?

更新

如果您有下面的 htaccess 代码...如何使用正则表达式使其更高效? 此外,就 SEO 而言,可访问页面(例如“tours/a.php”)是否应该重定向回“tours/a/”或主页?

我正在更新我网站的 url 结构。我正在重写的url还没有被爬取。

RewriteEngine on
Options -Indexes
RewriteRule ^tours/?$ tours.php
RewriteRule ^tours/a/?$ tours/a.php
RewriteRule ^tours/b/?$ tours/b.php
RewriteRule ^tours/c/?$ tours/c.php
RewriteRule ^tours/d/?$ tours/d.php
RewriteRule ^tours/e/?$ tours/e.php
RewriteRule ^tours/f/?$ tours/f.php
RewriteRule ^tours/g/?$ tours/g.php

【问题讨论】:

  • 是的,最好避免重复内容,所以从.php重定向回/tour
  • 设置重定向,不要忘记在标记中添加指向 site.com/tour 的规范链接。

标签: apache .htaccess redirect seo


【解决方案1】:

设置 301 重定向,以便索引旧 URL 的任何内容都将指向新 URL:

RewriteCond %{THE_REQUEST} \+ /tour-info\.php(\?|\ |$)
RewriteRule ^ /tour/ [L,R=301]

【讨论】:

  • RewriteRule ^/tour-info.php www.site.com/tour/ [R=301] 和 RewriteCond %{THE_REQUEST} \+ /tour-info\.php( \?|\ |$) 重写规则 ^ /tour/ [L,R=301]
  • @Obi-Wan RewriteRule 的正则表达式检查当前的 URI,这可能是浏览器请求的内容、之前被另一个重写规则重写的内容、内部重定向等。 %{THE_REQUEST} 变量只是浏览器请求的。
  • 如果您有时间,我将不胜感激您对我更新的原始问题的意见。非常感谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-12-21
  • 2015-03-04
  • 2014-11-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多