Forum Moderators: phranque

Message Too Old, No Replies

Help with htaccess (Rewrite for ~50K files)

Help write htaccess code to move files from Abc.html to A/Abc.html

         

VedranKovac

1:23 am on Dec 18, 2008 (gmt 0)

10+ Year Member



Hello All,

I am new to apache and I'd like to upload a .htaccess file.

I have around 50000 static html files that I'd like to redirect - the files are as follows:

www.example.com/Bero.html
www.example.com/Acrobat.html
www.example.com/Brak.html
www.example.com/Cengeritonex.html
www.example.com/WRCCane.html

I moved the files and the structure is now as follows:

www.example.com/A/Aero.html
www.example.com/A/Acrobat.html
www.example.com/B/Brak.html
www.example.com/C/Cengeritonex.html
www.example.com/W/WRCCane.html

Would someone be able to help me and provide guidance regarding how this can be accomplished.

Best,

Ira

jdMorgan

2:02 am on Dec 18, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That's a fairly simple one-line RewriteRule. So what have you tried so far?

Jim

g1smd

7:02 pm on Dec 18, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



In fact, instead of a redirect, it is also a fairly simple rewrite to keep the same URLs in use even though the files have moved to new folders on the server.

jdMorgan

12:01 am on Dec 19, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It appears that the files have been moved in order to improve performance only, as the filesystem gets very slow when a lot of files are in a single directory. So I think we can assume that the URLs are to stay the same here.

Jim

VedranKovac

6:37 am on Dec 19, 2008 (gmt 0)

10+ Year Member



jdMorgan - I tried this (after searching boards) to no avail: RedirectMatch 301 ^/(.)([^/]*)$ http://www.example.com/$1/$1$2

any suggestions on where I might have made the mistake?

g1smd - yes, I moved files due to performance issues.

jdMorgan

6:44 pm on Dec 19, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You did not comment on the discussion above, so I assume you are leaving the URLs unchanged (you should). So, this calls for an internal rewrite, not an external redirect.

RewriteRule ^(([A-Z])[^.]*\.html)$ /$2/$1 [L]

I assume you already have other working mod_rewrite code in your .htaccess file. If not, you will need to add either both of the following lines ahead of the rule, or only the second one. The only way to find out is to test:

Options +FollowSymLinks
RewriteEngine on

If the first letter might be lowercase, add "NC" to the flags, making them "[NC,L]"

Notice that using this rule requires that *all* .html files be moved into alphabetic subdirectories. If you need to add exceptions to this, then let us know.

Jim