3

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

goodeye
  • 2,389
  • 6
  • 35
  • 68
Timo77
  • 145
  • 1
  • 1
  • 19

2 Answers2

0

To make it valid 301 redirect just add the following flag at the end of the rule:

RewriteRule ^(\w+)/(\w+)/(\w+)/t_(\d+)/?$ /folderB/top.aspx?id=$4&linkki=$0 [NC,R=301,L]
TonyCool
  • 1,004
  • 1
  • 6
  • 5
  • at the end I want this url : http://www.domain.com/folderA/blabla/blalba/bla/t_2345/ To be redirected 301 to: http://www.domain.com/folderB/blabla/blalba/bla/t_2345/ – Timo77 May 07 '15 at 18:16
0

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

Community
  • 1
  • 1
goodeye
  • 2,389
  • 6
  • 35
  • 68