我设置了以下重写规则:
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]
不幸的是,这会导致我的服务器抛出500错误。单独来看,它们都可以正常工作。
我的意图是,如果请求为http://somesite.com/api/whatever/
,则会触发第一条规则,重定向到index.php/api/whatever/
如果“api”以外的任何内容作为第二段发送,它将重定向到index.php/other/whatever
。
我的理解是否存在缺陷?我认为它会从列表中下来,并且使用L标志,一旦它击中某个东西就会停止执行。或者我的语法错了?
干杯
答案 0 :(得分:2)
/var/log/httpd/error_log
(或系统上的等效路径。)[NC]
标志使[A-Za-z]
多余尝试:
RewriteRule ^api/([-A-Z0-9]+)$ index.php/api/$1 [NC,L]
RewriteRule ^([-A-Z0-9]+)$ index.php/other/$1 [NC,L]
或者
RewriteRule ^api/([^/]+)$ index.php/api/$1 [NC,L]
RewriteRule ^([^/]+)$ index.php/other/$1 [NC,L]
答案 1 :(得分:-1)
我认为您需要QSA
flag,请尝试:
RewriteRule ^api/(.*)$ index.php/api/$1 [QSA,NC,L]
RewriteRule ^(.*)$ index.php/other/$1 [QSA,NC,L]
答案 2 :(得分:-1)
在.htaccess文件中尝试以下规则:
RewriteEngine on
Options +FollowSymlinks -MultiViews
RewriteRule ^api/(.*)/?$ /index.php/api/$1 [NC,L]
RewriteCond %{REQUEST_URI} !^/index\.php/ [NC]
RewriteRule ^(.*)/?$ /index.php/other/$1 [NC,L]
在第二个RewriteRule之前添加这个RewriteCond是很重要的,以避免无限重定向。