Page 1 of 1

.htaccess Regex

Posted: Wed Jun 20, 2007 6:11 pm
by superdezign
Why doesn't .htaccess handle regex correctly? It can't compile this:

Code: Select all

^([^/\?]+?)(/|/?\?[^/]+)?$
Before, I basically hacked my way to making a "valid" regex for my website to be barely functional. However, I can't get it to handle regex correctly. Locally, the regex works fine, but not on my host's server. They have Apache 1.3 (I have Apache 2), so does that have to do with it?

Is anyone aware of what regex .htaccess can handle, and what it can't?

Posted: Wed Jun 20, 2007 6:27 pm
by Benjamin
I'm interested in this as well. I have seen regex on one box cause internal server errors on another. Never really looked into it though.

Posted: Wed Jun 20, 2007 7:01 pm
by superdezign
I've made an important advancement here. .htaccess (at least on this server) does not support optional subpatterns (? modifier on subpatterns). That's horrible, because that means I have to write out all of the different options.

Posted: Wed Jun 20, 2007 7:29 pm
by Benjamin
I believe the issue I had was with a ? as well.

Posted: Wed Jun 20, 2007 7:53 pm
by superdezign
Yeah, I can't even get (.*?)/ to work.

I've come up with a solution though. I'm writing a quick little URL parser class in PHP and rewriting the URL to just go to the page without sending any parameters. Then, in PHP, regex $_SERVER['REQUEST_URI']. This also preserves other GET variables in the URL (which was the reason I was trying to change my regex in the first place).

Posted: Wed Jun 20, 2007 11:10 pm
by feyd
Last I saw, Apache used POSIX regex, not PCRE.

Posted: Wed Jun 20, 2007 11:14 pm
by John Cartwright
Yup, if you take a look at http://httpd.apache.org/docs/2.0/new_features_2_0.html they briefly mention the upgrade.

Posted: Thu Jun 21, 2007 5:23 am
by superdezign
Ugh. 1.3 is such a waste of space.

I specifically request to be on their PHP5/MySQL 5 server, and it still uses Apache 1.3....