拥有庞大的重定向列表中的.htaccess的问题吗?重定向、庞大、问题、列表中

2023-09-02 00:44:40 作者:贪恋你的笑

我要重定向每一个帖子301重定向,但我有超​​过3000帖。

I want to redirect every post 301 redirect, but I have over 3000 posts.

如果我列出

Redirect permanent /blog/2010/07/post.html http://new.blog.com/2010/07/23/post/
Redirect permanent /blog/2010/07/post1.html http://new.blog.com/2010/07/24/post1/
Redirect permanent /blog/2010/07/post2.html http://new.blog.com/2010/07/25/post2/
Redirect permanent /blog/2010/07/post3.html http://new.blog.com/2010/07/26/post3/
Redirect per......

有关在.htaccess超过3000 URL重定向的命令将这个吃了我的服务器资源,或造成一些问题?林不知道怎么的.htaccess工作,但如果服务器看着这些名单页面,每次用户请求,我猜这将是一个资源占用。

for over 3000 url redirect command in .htaccess would this eat my server resource or cause some problem? Im not sure how .htaccess work but if the server is looking at these lists each time user requests for page, I would guess it will be a resource hog.

我不能使用RedirectMatch,因为我在新的URL添加日期变量。你有重定向这些职位的任何其他建议?还是我就好了?

I can't use RedirectMatch because I added date variable in my new url. Do you have any other suggestions redirecting these posts? Or am I just fine?

谢谢!

推荐答案

我不是一个Apache专家,所以我不能说是否没有3000重定向在.htaccess是个问题(虽然我的直觉告诉我,这可能是一个糟糕的主意)。然而,作为一个简单的解决您的问题,为什么不使用 mod_rewrite的以做你的重定向?

I am not an Apache expert, so I cannot speak to whether or not having 3,000 redirects in .htaccess is a problem (though my gut tells me it probably is a bad idea). However, as a simpler solution to your problem, why not use mod_rewrite to do your redirects?

RewriteRule ^/blog/(.+)/(.+)/(.+).html$ http://new.blog.com/$1/$2/$3/ [R=permanent]

此使用正则表达式匹配旧网址,并将其改写为新的。该 [R =永久] 指示的默默改写内部要求的mod_rewrite发出301新的URL来代替。

This uses a regex to match old URLs and rewrite them to new ones. The [R=permanent] instructs mod_rewrite to issue a 301 with the new URL instead of silently rewriting the request internally.

在你的榜样,它看起来像你的帖子的网址,而不会在旧的URL存在一天增加。既然你显然不能使用正则表达式可以洞察到任意的职位是做了一天,这种方法可能不适合你的工作。如果你可以从URL下降的那一天,那么你是好去。

In your example, it looks like you've added the day of the post to the URL, which does not exist in the old URL. Since you obviously cannot use a regexp to divine the day an arbitrary post was made, this method may not work for you. If you can drop the day from the URL, then you're good to go.

修改:我第一次看你的问题,我错过了最后一段。 (我不能使用RedirectMatch,因为我在新的URL添加日期变量。)在这种情况下,你可以使用mod_rewrite的的 RewriteMap指令查找一职当天的组成部分。

Edit: The first time I read your question, I missed the last paragraph. ("I can't use RedirectMatch because I added date variable in my new url.") In this case, you can use mod_rewrite's RewriteMap to lookup the day component of a post.

您有两种选择:

使用一个HashMap在一个静态文件进行快速查找。这意味着所有的旧网址的工作,但任何新的职位,不能用旧的URL方案来访问。 使用脚本抢的那一天。

在方案一中,创建一个名为posts.txt文件,并把:

In option one, create a file called posts.txt and put:

/yyyy/mm/pppp dd

...每一个岗位,其中yyyy一职的年份,mm是月份​​,而PPPP是后名(没有的.html)。

...for each post where yyyy is the year of the post, mm is the month, and pppp is the post name (without the .html).

当您完成后,运行:

$ httxt2dbm -i posts.txt -o posts.map 

然后我们添加到服务器/虚拟服务器配置:(注意路径是文件系统的路径,而不是URL。)

Then we add to to the server/virtual server config: (Note the path is a filesystem path, not a URL.)

RewriteMap postday dbm:/path/to/file/posts.map
RewriteRule ^/blog/(.+)/(.+)/(.+).html$ http://new.blog.com/$1/$2/${postday:$1/$2/$3}/$3/ [R=permanent]

在方案二中,使用 PGM:/path/to/script/lookup.whatever 为您RewriteMap指令。请参阅 mod_rewrite的文档有关使用脚本的详细信息。

In option two, use pgm:/path/to/script/lookup.whatever as your RewriteMap. See the mod_rewrite documentation for more info about using a script.

在做查询的mod_rewrite的不仅仅是重定向到一个脚本中查找日期,然后重定向到最终目的地,因为的你不应该重定向不止一次的。发出301或302招一个来回的成本,从而增加你的页面加载时间的延迟。

Doing the lookup in mod_rewrite is better than just redirecting to a script which looks up the date and then redirects to the final destination because you should never redirect more than once. Issuing a 301 or 302 incurs a round trip cost, which increases the latency of your page load time.

 
精彩推荐