简体   繁体   English

.htaccess 301重定向,URL具有不同的标识符

[英].htaccess 301 redirect, URLs have different identifiers

here is my problem. 这是我的问题。 Lets say these pages show details about a home that is being sold. 可以说,这些页面显示了有关待售房屋的详细信息。

I have an old URL like: 我有一个类似的旧网址:

www.example.com/home-details-12345.html

After a website redesign, the new URL looks like: 重新设计网站之后,新的URL如下所示:

www.example.com/new-york-home-56789/

Where 12345 and 56789 are both unique identifiers for that home. 其中1234556789都是该房屋的唯一标识符。 So, I'm trying to redirect an old URL that used id1 to identify the home in the database, to a new URL that uses another identifier, id2. 因此,我正在尝试将使用id1标识数据库中主目录的旧URL重定向到使用另一个标识符id2的新URL。 Basically, the URLs have nothing in common. 基本上,URL没有共同点。

I can however retrieve id2 based on id1. 但是,我可以基于id1检索id2。 So, my question is, how can I achieve this? 所以,我的问题是,我怎样才能做到这一点? Bear in mind there are over 100K homes, so manual redirects are out of the question. 请记住,这里有超过10万套房屋,因此手动重定向是不可能的。

I guess I need to make a RewriteRule for home-details-id1.html to a script, like getPage.php , where I can retrieve id2 using id1 , and make a second redirect to the correct page. 我想我需要为home-details-id1.html创建一个RewriteRule到脚本,如getPage.php ,在这里我可以使用id1检索id2 ,并进行第二次重定向到正确的页面。

But how do I do this? 但是我该怎么做呢? How will google handle this from a SEO point of view? Google将如何从SEO角度处理此问题? Thank you! 谢谢!

I'm no SEO expert, but I guess Google (or any other search engine for that matter) will recognize HTTP 301 redirection as "Moved permanently", so will try to index old URLs instead new ones. 我不是SEO专家,但我想Google(或与此有关的任何其他搜索引擎)会将HTTP 301重定向识别为“永久移动”,因此将尝试索引旧URL而不是新URL。 You could do a silent redirect by pointing Your RewriteRule to php script that would include old url (ie. include("home-details-12345.html"); ). 您可以通过将RewriteRule指向包含旧网址的php脚本(即include("home-details-12345.html"); )来进行无提示重定向。

However, that will produce quite a lot of overhead, and You really don't want to do that. 但是,这会产生很多开销,而您确实不想这样做。 Try to change Your software's logic so it complies with Your front-end - it's really the best practice for theese kind of issues, and even though it'll cost You some time, it WILL pay off in the future. 尝试更改您软件的逻辑,使其与您的前端兼容-这实际上是解决此类问题的最佳做法,尽管它会花费您一些时间,但将来会有所回报。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM