简体   繁体   English

Helicon ISAPI_Rewrite 301将某些文件从一个文件夹重定向到另一个文件夹

[英]Helicon ISAPI_Rewrite 301 redirect certain files from one folder to another

We moved our sites one folder to another folder. 我们将站点从一个文件夹移动到了另一个文件夹。 Some services we had to keep on old location still. 我们不得不将某些服务保留在旧位置上。 So we had to keep old the folder. 因此,我们必须保留旧文件夹。

We had this on our helicon ISAPI .htaccess file on root of FolderA 我们在FolderA根目录下的helicon ISAPI .htaccess文件中拥有此文件

RewriteRule ^(\w+)\/(\w+)\/(\w+)\/t_(\d+)\/ /folderA/top.aspx?id=$4&linkki=$0

How do we make 301 redirect to new location (folderB)? 我们如何使301重定向到新位置(文件夹B)? I know we could make this. 我知道我们可以做到这一点。

RewriteRule ^(\w+)\/(\w+)\/(\w+)\/t_(\d+)\/ /folderB/top.aspx?id=$4&linkki=$0 

But it is not the same as doing 301 redirect to user (and for search engines). 但这与301重定向到用户(对于搜索引擎)不同。

要使其有效301重定向,只需在规则末尾添加以下标志:

RewriteRule ^(\w+)/(\w+)/(\w+)/t_(\d+)/?$ /folderB/top.aspx?id=$4&linkki=$0 [NC,R=301,L]

To redirect the folderA to the folderB, you want to redirect as in your comment in the other answer. 要将文件夹A重定向到文件夹B,您需要按照其他答案中的注释进行重定向。

This will redirect /folderA/blabla/blalba/bla/t_2345 to /folderB/blabla/blalba/bla/t_2345 这会将/folderA/blabla/blalba/bla/t_2345/folderB/blabla/blalba/bla/t_2345

RewriteRule ^/folderA\/(\w+)\/(\w+)/(\w+)\/t_(\d+)$ /folderB/$1/$2/$3/t_$4 [NC,R=301,L]

If the number of folders changes, but they all end in t_digits, you could look for anything between the folderA and the t_digits. 如果文件夹的数量发生变化,但是它们都以t_digit结尾,则可以在folderA和t_digits之间寻找任何内容。 eg, this will redirect /folderA/abcdef/t_1234 to /folderB/abcdef/t_1234 例如,这会将/folderA/abcdef/t_1234重定向到/folderB/abcdef/t_1234

RewriteRule ^/folderA\/(.+)\/t_(\d+)$ /folderB/$1/t_$2 [NC,R=301,L]

You may have to adjust whether to keep the leading slash, depending on how things are configured. 您可能必须根据事物的配置方式来调整是否保留前导斜线。 Also, your question has a trailing slash, but the comment examples don't, so add or remove a trailing slash depending what you really need. 另外,您的问题带有斜杠,但注释示例没有,因此请根据实际需要添加或删除斜杠。

EDIT: A side note about the permanent redirect. 编辑:关于永久重定向的旁注。 While debugging this, use [NC,R,L] without the 301. When the redirect is permanent (301), the browser often caches a previous rule. 进行调试时,请使用不带301的[NC,R,L] 。当重定向为永久(301)时,浏览器通常会缓存以前的规则。 When done testing, change it to permanent. 完成测试后,将其更改为永久。 See number 2 and 3 in this answer: https://stackoverflow.com/a/9204355/292060 请参阅此答案中的2和3: https//stackoverflow.com/a/9204355/292060

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

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