PHP Rest API,重定向后路由器
我正在尝试编写一个简单的RESTful php应用程序。我正在尝试编写一个index.php路由器 我当前拥有的.htaccess文件是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
<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