SEO的.htaccess后重定向页面链接升级? [英] Redirecting page links after .htaccess SEO upgrade?

查看:138
本文介绍了SEO的.htaccess后重定向页面链接升级?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不想在这里膨胀一岗一吨的.htaccess的问题,所以我打破它们分别。这一次,是因为有使用 RedirectMatch 以创建为现有的,索引的网页是一个现有的网站的一部分的规则。

具体而言,我的测试网站已经运行了大约一年,我现在用的.htaccess为更好的搜索引擎优化重写干净的URL。所以,当我有,其内容根据查询字符串被称为一个链接,像这样一个容器页面:

http://www.website.com/departments.php?dep=contact_us

我的工作使URL看起来更平滑,如:

http://www.website.com/contact-us/

我阅读教程建议改变我的链接到新的,snazzier搜索引擎友好的风格,将导致大量的404错误和破碎的网页链接到该网站已被重新索引和记录带来了最新的。

因此​​,我的问题:这是一个合理的担忧或将新的联系被拾起在24-48小时内

我问,因为我有几个网站与文件结构的多层次,我想,我需要在我的.htaccess文件中的规则,一吨修复所有损坏的链接我可以创造。

如果我在这里制造混乱,请让我知道,我会澄清的事情。

提前感谢!

解决方案
  

因此​​,我的问题:这是一个合理的担忧或将新的联系被拾起在24-48小时内

您可以把它迟早会发生,如果你使用的是301(永久)重定向外部客户端。这比内部重写在服务器的结束,因为你会引起冲突的规则麻烦很多。例如,如果你想重写URL,一个以URL-B内部的服务器上,然后重定向的URL-B浏览器的URL一个(意为当客户端特别请求的URL-B重定向到URL的一个)

 #内部重写URL-A(假冒URL)给url-B(其中实际内容)
重写规则^ URL-A $ / URL-B [L]

#外部重定向URL-B(实际内容)的URL一个(假的URL)
重写规则^ URL-B $ / URL-A [L,R = 301]
 

由于重写引擎循环,这条规则将继续改写彼此并导致500内部服务器错误(如果更换了第二条规则同样的事情发生 RedirectMatch )。为了解决这个问题,你需要创建一个条件,使外部重定向(第二条规则)只被应用如果在实际要求对于URL-B。你可以通过匹配对%{THE_REQUEST} 变量,它实际上是一个HTTP请求的第一行上做到这一点。

使用你的榜样的网址,你有这样的事情:

 重写规则^接触-US /?$ /departments.php?dep=contact_us [L]

的RewriteCond%{THE_REQUEST} ^(GET | HEAD)\ /departments\.php\?dep=contact_us
重写规则^ /接触-US / [L,R = 301]
 

这意味着当有人像谷歌,机器人将尝试解析 http://www.website.com/departments.php?dep=contact_us ,第二个规则的条件将符合要求(这看起来是这样: GET /departments.php?dep=contact_us HTTP / 1.1 ),它会重定向到 HTTP ://www.website.com/contact-us/ 。在这一点上,客户端(谷歌机器人)将要求 /接触-US / 和第一个规则将得到应用和内部重写的URI /departments.php?dep=contact_us

I didn't want to bloat one post here with a ton of .htaccess questions, so I'm breaking them up individually. This one has to do with using RedirectMatch to create rules for existing, indexed pages that are part of an existing website.

Specifically, my test site has been up for about a year and I am now using .htaccess to re-write clean URLs for better SEO. So when I had a container page whose content was called based on a query string in a link, like so:

http://www.website.com/departments.php?dep=contact_us

I'm working on making the URL appear smoother like:

http://www.website.com/contact-us/

The tutorial I read suggested that changing my links to the new, snazzier SEO-friendly style would lead to lots of 404 errors and broken page links until the site has been indexed again and the records brought up to date.

Thus, my question: Is this a legitimate concern or will the new links be picked up in 24-48 hours?

I ask because I have several websites with many layers of file structure and I'm thinking that I'd need a TON of rules in my .htaccess file to fix all the broken links I may be creating.

If I'm creating confusion here, please let me know and I'll clarify things.

Many thanks in advance!

解决方案

Thus, my question: Is this a legitimate concern or will the new links be picked up in 24-48 hours?

You can make it happen sooner if you externally redirect the client using a 301 (permanent). This is a lot trickier than internally rewriting on the server's end because you'll cause conflicting rules. For example, if you wanted to rewrite url-a to url-b internally on the server, then redirect the browser from url-b to url-a (meaning when a client specifically requests url-b to redirect it to url-a):

# internally rewrite url-a (fake URL) to url-b (where the actual content is)
RewriteRule ^url-a$ /url-b [L]

# externally redirect url-b (actual content) to url-a (fake URL)
RewriteRule ^url-b$ /url-a [L,R=301]

Since the rewrite engine loops, these 2 rules will continue to rewrite each other and cause a 500 internal server error (the same thing happens if you replace the second rule with a RedirectMatch). To fix this, you need to create a condition so that the external redirect (second rule) only gets applied if the actual request was for "url-b". You can do this by matching against the %{THE_REQUEST} variable, which is essentially the first line of an HTTP request.

Using your example URLs, you'd have something like this:

RewriteRule ^contact-us/?$ /departments.php?dep=contact_us [L]

RewriteCond %{THE_REQUEST} ^(GET|HEAD)\ /departments\.php\?dep=contact_us
RewriteRule ^ /contact-us/ [L,R=301]

This means when someone like a google-bot attempts to resolve http://www.website.com/departments.php?dep=contact_us, the 2nd rule's condition will match the request (which will look something like: GET /departments.php?dep=contact_us HTTP/1.1) and it will get redirected to http://www.website.com/contact-us/. At which point, the client (google-bot) will request /contact-us/ and the first rule will get applied and internally rewrite the URI to /departments.php?dep=contact_us.

这篇关于SEO的.htaccess后重定向页面链接升级?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆