使用PHP在Apache2.4上配置RESTful虚拟主机
我正试图在我的Apache2.4服务器(Ubuntu)上的VirtualHost上创建一个RESTful API。我有一个名为使用PHP在Apache2.4上配置RESTful虚拟主机,php,apache,rest,http,mod-rewrite,Php,Apache,Rest,Http,Mod Rewrite,我正试图在我的Apache2.4服务器(Ubuntu)上的VirtualHost上创建一个RESTful API。我有一个名为dbManager.php的php文件,我正在使用重写规则使其看起来像一个api目录。除了PUT和DELETE命令(返回403个错误)之外,它工作得非常好。以下是我的conf文件的修订版本: <VirtualHost *> ServerAdmin onigame@gmail.com ServerName servername.com ServerA
dbManager.php
的php文件,我正在使用重写规则使其看起来像一个api
目录。除了PUT和DELETE命令(返回403个错误)之外,它工作得非常好。以下是我的conf文件的修订版本:
<VirtualHost *>
ServerAdmin onigame@gmail.com
ServerName servername.com
ServerAlias *.servername.com
DirectoryIndex index.html index.php
DocumentRoot /path/to/local/dir/
<Directory />
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
<Limit PUT DELETE>
Require all granted
</Limit>
</Directory>
# RESTful services provided for the fake "api" directory
RewriteEngine on
RewriteRule ^/api/(.*)$ /dbManager.php/$1 [L]
ServerSignature On
AddDefaultCharset utf-8
</VirtualHost>
服务器管理员onigame@gmail.com
ServerName ServerName.com
ServerAlias*.servername.com
DirectoryIndex.html index.php
DocumentRoot/path/to/local/dir/
选项索引跟随符号链接多视图
允许超越所有
要求所有授权
要求所有授权
#为假“api”目录提供RESTful服务
重新启动发动机
重写规则^/api/(.*)$/dbManager.php/$1[L]
服务器签名
AddDefaultCharset utf-8
嗯,PUT和DELETE仍然不起作用,返回403。我还担心,我真的不想允许在目录中的任何地方进行PUT和DELETE操作,而只是通过伪
api
目录。做这件事的正确方法是什么?我已经设法解决了我的问题,但我真的不明白它为什么有效:
<VirtualHost *>
ServerAdmin onigame@gmail.com
ServerName servername.com
ServerAlias *.servername.com
DirectoryIndex index.html index.php
DocumentRoot /path/to/local/dir/
<Directory />
Options Indexes FollowSymLinks MultiViews
AllowOverride All
</Directory>
<Directory /path/to/local/dir/>
Require all granted
Satisfy All
</Directory>
# RESTful services provided for the fake "api" directory
RewriteEngine on
RewriteRule ^/api/(.*)$ /dbManager.php/$1 [L]
ServerSignature On
AddDefaultCharset utf-8
</VirtualHost>
服务器管理员onigame@gmail.com
ServerName ServerName.com
ServerAlias*.servername.com
DirectoryIndex.html index.php
DocumentRoot/path/to/local/dir/
选项索引跟随符号链接多视图
允许超越所有
要求所有授权
满足所有
#为假“api”目录提供RESTful服务
重新启动发动机
重写规则^/api/(.*)$/dbManager.php/$1[L]
服务器签名
AddDefaultCharset utf-8
据我所知,得到403意味着它的访问被阻止,而不是HTTP请求的类型(这将导致405,而不是403)。而访问问题是在本地目录上,因此需要为其设置一个特殊的部分。但我真的不明白为什么我放在那里的两条线能让事情顺利进行。Require
指令,这是有意义的。但是满足
指令,从中可以看出,应该默认为All
然而,当我删除任何一行时,它都不起作用