Forum Moderators: phranque

Message Too Old, No Replies

RewriteRule multiple $ GET vars problem

A RewriteRule line with multiple GET vars works on one server, not another

         

deathpie

1:05 pm on Jun 1, 2009 (gmt 0)

10+ Year Member



I have a RewriteRule that works on one server but not another. The rule takes a url like this:

http://www.example.com/sectionName/pageName/

...and parses out the 2 GET variables to load a page like this:

http://www.example.com/pages.php?page=pageName&section=sectionName

Here's the htaccess script:

RewriteEngine On
RewriteRule ^([a-zA-Z0-9\-\_\ \%]+)/([a-zA-Z0-9\-\_\ \%]+)/?$ pages.php?page=$2&section=$1 [L]

This works fine on one server, but not another. I believe the problem is that it won't parse out the two variables that are separated by a slash. Instead, it treats them as one long variable named "page" -- pageName&section=sectionName.

Any help is greatly appreciated.

Thanks.

[edited by: jdMorgan at 1:28 pm (utc) on June 1, 2009]
[edit reason] example.com [/edit]

jdMorgan

1:27 pm on Jun 1, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's not likely a parsing error as you describe... This module has been parsing slash-separated variables for a long, long time -- and on millions of servers.

Taking several shots in the dark here, I'm going to guess that MultiViews may be interfering, that the 'hyphen escaping bug' in alternate character groups may be causing a problem, or that you need to use the [NE] flag on the rule, because your URLs evidently contain percent signs which should be escaped.

Note that the [NC] flag is used for efficiency, allowing us to speed up the pattern matching about 30% by eliminating "A-Z" from the two subpatterns.


Options +FollowSymLinks -MultiViews
RewriteEngine On
#
RewriteRule ^([a-z0-9_%\ \-]+)/([a-z0-9_%\ \-]+)/?$ pages.php?page=$2&section=$1 [[b]NC,NE[/b],L]

If this doesn't help, look into disabling AcceptPathInfo [httpd.apache.org] if you're on Apache 2.x -- It can also interfere with mod_rewrite.

Also, look for other rules in your other config and .htaccess files that may rewrite this URL-pattern before this rule gets control.

Finally, if you just want to parse slash-separated fields, then a pattern like "([^/]+)/([^/]+)/?$ would be more efficient.

Jim

deathpie

2:19 pm on Jun 8, 2009 (gmt 0)

10+ Year Member



We've figured out the problem. It ended up being a combination of your suggestions, some tweaking
with apache, and trial and error. I guess the problem was specific to Apache 1.3. We ended up using this:

Options +FollowSymLinks -MultiViews
RewriteEngine On

RewriteRule ^([a-z0-9_%\ \-]+)/([a-z0-9_%\ \-]+)/?$ pages.php?page=$2&section=$1 [NC,NE,L]

Thanks for the help!

jdMorgan

2:41 pm on Jun 8, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Interestingly, I also encountered the "escaped hyphen must be the last character in the alternate-character [group] on some servers" problem myself last week -- after posting my reply.

If you had posted your question only a few days later, I might have spotted that problem. But unfortunately, we both had to learn the hard way... :(

Jim

[edited by: jdMorgan at 2:42 pm (utc) on June 8, 2009]