Forum Moderators: phranque

Message Too Old, No Replies

Consolidating 3 rewrite rules into 1

is this the best way?

         

StaceyJ

4:10 pm on Dec 30, 2010 (gmt 0)

10+ Year Member



I have a URL that looks like this

http://www.example.com/dir1/dir2/prodid.123456789

but /dir2 and /dir2/prodid.123456789 don't always have to exist. The following 3 rewrites have been tested and work to rewrite the new URL's back to the old filepaths

RewriteRule ^([^\./]+)/([^\./]+)/([^/]+)$ /cgi-bin/store/$1.cgi/$2/$3 [L]
RewriteRule ^([^\./]+)/([^\./]+)$ /cgi-bin/store/$1.cgi/$2 [L]
RewriteRule ^([^\./]+)$ /cgi-bin/store/$1.cgi [L]

I'd like to consolidate them if it would be more efficient, would this be the best way to accomplish that?

RewriteRule ^([^\./]+)([^\ ]+)* $ /cgi-bin/store/$1.cgi$2 [L]

I also think I could use (.*) instead for the second part, but I keep reading how it is best not to use it under various situations. Would that also apply here?

Thank you!

jdMorgan

5:30 pm on Jan 5, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Include the slash preceding all optional subdirectories after the first level. I'd suggest:

RewriteRule ^([^/.]+)(/[^/.]+)*$ /cgi-bin/store/$1.cgi$2 [L]

It is not necessary to escape literal periods within alternate-character groups.

Jim