Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess 多重重写规则不起作用_.htaccess_Mod Rewrite_Url Rewriting - Fatal编程技术网

.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。如果没有它,我就得到了一个404with
api.php
?它是否在
api/
目录中?看起来这从一开始就起作用了,但由于某种原因,我的框架以一种意外的方式运行。。。