Forum Moderators: phranque
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!
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]
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?