简体   繁体   中英

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

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.

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重定向,只需在规则末尾添加以下标志:

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.

This will redirect /folderA/blabla/blalba/bla/t_2345 to /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. eg, this will redirect /folderA/abcdef/t_1234 to /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://stackoverflow.com/a/9204355/292060

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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