Forum Moderators: phranque

Message Too Old, No Replies

Global 301 Solution

without affecting new files in dir?

         

jk3210

7:55 pm on Jul 18, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have to re-name a series of 80 urls so that their new file names contain 3 digits...

Example: /dir/file-3.htm to /dir/file-003.htm

Files are numbered 1 thru 80.

To 301 from OLD to NEW file names, does this mean I must do a 301 entry for *each* file name like so...

Redirect 301 /dir/file-3.htm http*//www.domain.com/dir/file-003.htm
Redirect 301 /dir/file-4.htm http*//www.domain.com/dir/file-004.htm
Redirect 301 /dir/file-5.htm http*//www.domain.com/dir/file-005.htm

...or is there a global way to do the 301 to the new file names, without affecting future files that are created passed number 80 in that dir?

Thanks

jdMorgan

8:26 pm on Jul 18, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No. Use RedirectMatch [httpd.apache.org] to 'correct' all old one- and two-digit URLs:

RedirectMatch 301 ^/dir/file-([1-9])\.htm$ http://www.example.com/dir/file-00$1.htm
RedirectMatch 301 ^/dir/file-([1-7][0-9])\.htm$ http://www.example.com/dir/file-0$1.htm

The $1 token in the new URL back-references the file number provided in the originally-requested URL and matched by the parenthesized regular-expressions pattern, "copying" it into the new URL.

Jim

[edit] Sorry, missed the "past 80" bit on the first try. [/edit]

[edited by: jdMorgan at 8:29 pm (utc) on July 18, 2006]

jk3210

9:13 pm on Jul 18, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Works!

Thanks Jim