Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite w/ chars & nums

         

ladams02

10:12 pm on Sep 14, 2006 (gmt 0)

10+ Year Member



I'm having trouble rewriting a URL when a numeric value is used instead of chars.

For example, this will rewrite correctly: ../gender/male/

But this will generate error: ../age/21/

Here is what I'm using in my .htaccess file:


RewriteCond %{REQUEST_FILENAME}!-f
RewriteRule ^([^/]+)/([^/]+)/?$ /community_luke/browse.php?$1=$2 [L]

Thanks!

jdMorgan

10:42 pm on Sep 14, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I assume you mean a 404-Not found error. If that's the case, then unless there is a directory on your server named /age/21/ there is no reason your code should not work as posted regardless of the characters in the URL. The only character that won't be "allowed within a parameter" is "/", since that is your parameter separator as coded in the rule pattern.

Note that a URL ending with a slash is a directory, so your should check for -d instead of -f. If you wish to accept URLs that do or do not end with a slash --as implied by the "/?" at the end of your regex pattern-- then you should check for both -f and -d.

Be sure that there are no other Redirects or rewriterules preceding this one or in a higher-level directory .htaccess file or server config file that might be intercepting these numeric-field URLs and interfering with your rule. Note that on most servers, any Redirect or RedirectMatch directives in your files will be executed before mod_rewrite directives, even if they follow the mod_rewrite directives; Each Apache module parses config files in turn, in the reverse order specified by LoadModule, and executes all the directives it understands. Therefore your directives for any one given module will execute in the order you specify, but each module itself will execute *all* of the directives it understands in LoadModule order, and not in the order specified by your code.

It is also possible that you have an old or corrupt installation of the POSIX regular-expressions library on your server. If so then it will need to be updated or reinstalled. Or if that's the case and you can't update/reinstall, you might also try a work-around, such as:


RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^a-z0-9]+)/?$ /community_luke/browse.php?$1=$2 [NC,L]

Jim

ladams02

11:02 pm on Sep 14, 2006 (gmt 0)

10+ Year Member



Hey thanks for the reply Jim!

I have a feeling this rule is conflicting with another one in my .htaccess file. I'm configuring a pre-written script so there is a lot going on that I'm not quite sure about yet. I'm going to stip the file down and see if I can get this one rule working alone.

But when dealing with multiple rules like this I'm finding them often conflicting with one another. Is it good practice to indicate whether a rule is looking for character or numeric anchor? Or is there anything else I can do to keep these rules from conflicting with one another?