Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.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
PHP Rest API,重定向后路由器_Php_Regex_Apache_.htaccess_Rest - Fatal编程技术网

PHP Rest API,重定向后路由器

PHP Rest API,重定向后路由器,php,regex,apache,.htaccess,rest,Php,Regex,Apache,.htaccess,Rest,我正在尝试编写一个简单的RESTful php应用程序。我正在尝试编写一个index.php路由器 我当前拥有的.htaccess文件是 <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$ RewriteRule api/^(.*)$ api/index.php?_url=/$1

我正在尝试编写一个简单的RESTful php应用程序。我正在尝试编写一个index.php路由器

我当前拥有的.htaccess文件是

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule api/^(.*)$ api/index.php?_url=/$1 [QSA,L]
</IfModule>
其中
controller.php
位于
/var/www/api

Vhost文件在
/etc/apache2/站点中可用

标题为api.conf

看起来是这样的:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ controller.php?do=$1 [L,QSA]
<VirtualHost *:*>
    ServerName test.example.com
    ServerAlias www.test.example.com
    DocumentRoot /var/www/api/
    <Directory "/var/www/api/">
        Allow from all
        AllowOverride all
        Options +Indexes
    </Directory>
</VirtualHost>
我解决了这个问题:

当我执行更新时,Apache在sites available文件夹中重写了
default.conf
文件,但我忽略了

我需要添加到
000 default.conf

<Directory /var/www/>
     AllowOverride All
因此,要重新启用:

a2enmod rewrite

service apache2 restart
希望这能帮助别人

in_array('mod_rewrite', apache_get_modules());
//or
var_dump(apache_get_modules());
a2enmod rewrite

service apache2 restart