Search code examples
http-redirecthttp-status-code-301isapi-rewritehelicontech

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).


Solution

  • 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. e.g., 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