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 though开发者_如何转开发t 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
- whenever you get a 500, check
/var/log/httpd/error_log
(or the equivalent path on your system.) - 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]
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]
精彩评论