Forum Moderators: phranque

Message Too Old, No Replies

Mod Rewrite HELP!

I cant figure this one out

         

Bonusbana

12:21 pm on Aug 20, 2004 (gmt 0)

10+ Year Member



Hi

I have a mod rewrite that looks like this in the .htaccess:

Options +FollowSymLinks
RewriteEngine on

RewriteBase /

RewriteRule ^(.*)/(.*)\.htm$ /index\.php?section=$1&sub=$2
RewriteRule ^(.*)\.htm$ /index\.php?section=$1

Now, I thought that a url like:
site.com/section/sub.htm

would generate a:
site.com/index.php?section=section&sub=sub

since the first rule should apply first.
However, when typing the example url, it generates a:
site.com/index.php?section=index.php/sub&sub=

If I remove the second rule, it generates fine.
How come the second rule have superior priority, when the first rule comes first?

Thanks
David

gergoe

12:56 pm on Aug 20, 2004 (gmt 0)

10+ Year Member



Try this one instead:

RewriteRule ^([^/]+)/([^/]+)\.html?$ /index\.php?section=$1&sub=$2
RewriteRule ^([^/]+)\.html?$ /index\.php?section=$1

This is more strict on the regular expressions, it forces the correct apperance and number fo the slashes in the url. The [^/] means; match everything except the slash character. The \.html? pattern matches .htm and .html also (to be on the safe side), you can take it off, if you are sure that the correct one is used all the time.

Bonusbana

1:04 pm on Aug 20, 2004 (gmt 0)

10+ Year Member



Thank you!

Worked like a charm.
I must study the reg exp more i guess...