.htaccess 多重重写规则不起作用
这是我当前的.htaccess 多重重写规则不起作用,.htaccess,mod-rewrite,url-rewriting,.htaccess,Mod Rewrite,Url Rewriting,这是我当前的.htaccess文件 <IfModule mod_env.c> SetEnv CI_ENV development </IfModule> Options -Indexes RewriteEngine on RewriteBase RewriteCond $1 !^(index\.php|resources|robots\.txt) [NC] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{
.htaccess
文件
<IfModule mod_env.c>
SetEnv CI_ENV development
</IfModule>
Options -Indexes
RewriteEngine on
RewriteBase
RewriteCond $1 !^(index\.php|resources|robots\.txt) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
现在我想做的是有一个文件名api.php
,当URL指向api
文件夹时,需要激活这个文件。例如:
http://example.com/ => Call index.php file
http://example.com/index.php => Call index.php file
http://example.com/index/ => Call index.php file
http://example.com/api/ => Call index.php file
http://example.com/api/add => Call index.php file
http://example.com/api/delete => Call index.php file
http://example.com/post/ => Call index.php file
http://example.com/post/hello => Call index.php file
http://example.com/ => Call index.php file
http://example.com/index.php => Call index.php file
http://example.com/index/ => Call index.php file
http://example.com/api/ => Call api.php file
http://example.com/api/add => Call api.php file
http://example.com/api/delete => Call api.php file
http://example.com/post/ => Call index.php file
http://example.com/post/hello => Call index.php file
您可以使用:
<IfModule mod_env.c>
SetEnv CI_ENV development
</IfModule>
Options -Indexes
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^api/(.*)$ api.php?/$1 [NC,L,QSA]
RewriteCond $1 !^(index\.php|resources|robots\.txt) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
SetEnv CI_环境开发
选项-索引
重新启动发动机
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^api/(*)$api.php?/$1[NC,L,QSA]
1美元^(索引\.php | resources | robots\.txt)[NC]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)$index.php?/$1[L,QSA]
这会产生一个错误500:RewriteBase接受一个参数,即每个目录上下文的基本URL。如果没有它,我就得到了一个404withapi.php
?它是否在api/
目录中?看起来这从一开始就起作用了,但由于某种原因,我的框架以一种意外的方式运行。。。