Nathan Kunicki
Nathan Kunicki

Reputation: 11

RewriteRule 500 Error Question

I have the following Rewrite Rules set up:

RewriteEngine On

RewriteRule ^api/([A-Za-z0-9-]+)$ index.php/api/$1 [NC,L]
RewriteRule ^([A-Za-z0-9-]+)$ index.php/other/$1 [NC,L]

Unfortunately these cause my server to throw a 500 error. Taken individually, they both work fine though.

My intention is that if the request is http://somesite.com/api/whatever/, the first rule will get triggered, redirecting to index.php/api/whatever/

If anything other than "api" gets sent as the second segment though, it will redirect to index.php/other/whatever.

Is my understanding flawed somehow? I thought that it would go down the list, and with the L flag, would stop executing once it hit something. Or is my syntax wrong?

Cheers

Upvotes: 1

Views: 974

Answers (2)

Frank Farmer
Frank Farmer

Reputation: 39366

  1. whenever you get a 500, check /var/log/httpd/error_log (or the equivalent path on your system.)
  2. I'm pretty sure the hyphen char in your character group is a regex syntax error. (also, the [NC] flag makes [A-Za-z] redundant

Try:

RewriteRule ^api/([-A-Z0-9]+)$ index.php/api/$1 [NC,L]
RewriteRule ^([-A-Z0-9]+)$ index.php/other/$1 [NC,L]

Or perhaps

RewriteRule ^api/([^/]+)$ index.php/api/$1 [NC,L]
RewriteRule ^([^/]+)$ index.php/other/$1 [NC,L]

Upvotes: 2

Bil
Bil

Reputation: 543

I think you need QSA flag, try like that :

RewriteRule ^api/(.*)$ index.php/api/$1 [QSA,NC,L]
RewriteRule ^(.*)$ index.php/other/$1 [QSA,NC,L]

Upvotes: -1

Related Questions