Forum Moderators: phranque

Message Too Old, No Replies

folder and file structure rename

always check your code

         

smallcompany

8:45 pm on Feb 22, 2010 (gmt 0)

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



This is a story about resolved problem - syntax issue - simple stuff as in most of cases.

It happened that the folder and file names within it had to be renamed.

As the file names have a pattern, I thought that two lines should do it, rather than one line for each page.

Basically a folder is being renamed from /a1-a2-a3/ to /a1-a2/, and files from /something-a2-a3.html to /something-a2.html

I already have an entry that rewrites all subfolder index.html files to a subfolder itself, so any request for index.html file goes to / of the page.

Based on the above, I came up with two lines of 301:

RewriteRule ^a1-a2-a3/$ http://www.example.com/a1-a2/ [R=301,L]
RewriteRule ^a1-a2-a3/(*.)-a2-a3\.html$ http://www.example.com/a1-a2/$1-a2.html [R=301,L]

I got 500...

I tested each line separately, and got that only the second one causes 500.

Then I searched and came to another post at WW, and found this:

RedirectMatch 301 ^/the_old_([^.]+)\.htm$ http://example.com/the-new-$1.htm

I decided to go step by step, so I left RewriteRule, but replaced my (*.) with ([^.]+) - and it worked.

Then, I wanted to double check, and finally found that my only problem was the syntax as (*.) should actually be (.*)

Arghhh... always check the code again and again.

Anyway, based on the bad experience from the above, I wonder about:

- Difference in using (.*) vs. ([^.]+)
- Difference in using RedirectMatch vs. RewriteRule


Thanks

g1smd

8:52 pm on Feb 22, 2010 (gmt 0)

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



The .* pattern matches the whole request then has to back off and retry hundreds or thousands of times to find a match.

Any "not" pattern [^ .. ]+ will be able to be parsed from left to right in one cycle.

smallcompany

12:37 am on Feb 23, 2010 (gmt 0)

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



"not" pattern ([^.]+)


- does this mean the "not" pattern is faster?
- when would you use (.*), but not ([^.]+)

Thanks

g1smd

12:41 am on Feb 23, 2010 (gmt 0)

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



I would use .* in a pattern like
^somestuff/whatever(.*)
to match the rest of the string after some 'fixed' items.

I wouldn't use
(.*)somestuff$
or
(.*)/(.*)
as that's always a whole lot of trouble.

jdMorgan

2:53 pm on Feb 23, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> does this mean the "not" pattern is faster?

Certainly. Matching a specific pattern is always "faster" than matching an ambiguous pattern.

Jim