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)? I know we could make this.
我们如何让301重定向到新位置(folderB)?我知道我们可以做到这一点。
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重定向到用户(以及搜索引擎)不同。
2 个解决方案
#1
To redirect the folderA to the folderB, you want to redirect as in your comment in the other answer.
要将folderA重定向到folderB,您需要在其他答案的注释中重定向。
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. e.g., this will redirect /folderA/abcdef/t_1234
to /folderB/abcdef/t_1234
如果文件夹的数量发生了变化,但它们都以t_digits结尾,那么您可以查找folderA和t_digits之间的任何内容。例如,这会将/ 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. When done testing, change it to permanent. See number 2 and 3 in this answer: https://*.com/a/9204355/292060
编辑:关于永久重定向的附注。在调试时,使用[NC,R,L]而不使用301.当重定向是永久性的(301)时,浏览器通常会缓存先前的规则。完成测试后,将其更改为永久性。请参阅此答案中的第2和第3位:https://*.com/a/9204355/292060
#2
To make it valid 301 redirect just add the following flag at the end of the rule:
要使其有效301重定向,只需在规则末尾添加以下标志:
RewriteRule ^(\w+)/(\w+)/(\w+)/t_(\d+)/?$ /folderB/top.aspx?id=$4&linkki=$0 [NC,R=301,L]
#1
To redirect the folderA to the folderB, you want to redirect as in your comment in the other answer.
要将folderA重定向到folderB,您需要在其他答案的注释中重定向。
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. e.g., this will redirect /folderA/abcdef/t_1234
to /folderB/abcdef/t_1234
如果文件夹的数量发生了变化,但它们都以t_digits结尾,那么您可以查找folderA和t_digits之间的任何内容。例如,这会将/ 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. When done testing, change it to permanent. See number 2 and 3 in this answer: https://*.com/a/9204355/292060
编辑:关于永久重定向的附注。在调试时,使用[NC,R,L]而不使用301.当重定向是永久性的(301)时,浏览器通常会缓存先前的规则。完成测试后,将其更改为永久性。请参阅此答案中的第2和第3位:https://*.com/a/9204355/292060
#2
To make it valid 301 redirect just add the following flag at the end of the rule:
要使其有效301重定向,只需在规则末尾添加以下标志:
RewriteRule ^(\w+)/(\w+)/(\w+)/t_(\d+)/?$ /folderB/top.aspx?id=$4&linkki=$0 [NC,R=301,L]