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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/rest/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的HTTPS和REST API_.htaccess_Rest_Ssl_Https_Apache2 - Fatal编程技术网

带有.htaccess的HTTPS和REST API

带有.htaccess的HTTPS和REST API,.htaccess,rest,ssl,https,apache2,.htaccess,Rest,Ssl,Https,Apache2,首先,我在apache2服务器上使用以下.htaccess文件为我的REST API实现了重写规则: <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-s RewriteRule ^(.*)$ index.php?rquest=$1 [QSA,NC,L] Rewrit

首先,我在apache2服务器上使用以下
.htaccess
文件为我的REST API实现了重写规则:

<IfModule mod_rewrite.c>
    RewriteEngine On 

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-s
    RewriteRule ^(.*)$ index.php?rquest=$1 [QSA,NC,L]

    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^(.*)$ index.php [QSA,NC,L]

    RewriteCond %{REQUEST_FILENAME} -s
    RewriteRule ^(.*)$ index.php [QSA,NC,L] 
</IfModule>
RewriteCond %{SERVER_PORT}   !^443$
RewriteRule  (.*)  https://%{HTTP_HOST}/$1   [L]
现在我收到一个页面未找到错误。您能在
.htaccess
文件中看到错误吗,还是必须在其他地方?我对这些文件不太熟悉。为了创建我的API,我使用了。

在的帮助下,我找到了解决方案

当我更新我的服务器以使用
https
myfolder
sites enabled
运行时,包含了一个新文件
sites enabled/default ssl
。在这个文件中,我必须设置

AllowOverride All
就像我已经在使用http
http
时对上所做的那样。我补充说,
.htaccess
文件的正确解决方案如下:

<IfModule mod_rewrite.c>
    RewriteEngine On 

    #use https
    RewriteCond %{SERVER_PORT}   !^443$
    RewriteRule  (.*)  https://%{HTTP_HOST}/%{REQUEST_URI}  [L]

    #used for api
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-s
    RewriteRule ^(.*)$ index.php?rquest=$1 [QSA,NC,L]

    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^(.*)$ index.php [QSA,NC,L]

    RewriteCond %{REQUEST_FILENAME} -s
    RewriteRule ^(.*)$ index.php [QSA,NC,L] 
</IfModule>

因为
$1
在下一条规则中被覆盖了。

您可以使用
https://domain.com/REST/SomeRule/12
URL?没有,我也尝试过。因此,它可能不适用于我的api。正如我所说,我遵循了问题中链接的教程。如果您使用
https://domain.com/REST/SomeRule/12
此外,您可能没有正确设置SSL站点。为https站点提供
VirtualHost
config以便
https://domain.com/REST/SomeRule/12
上面写着:
在这台服务器上找不到请求的URL/REST/SomeRule/12。
看来,到index.php的链接不起作用。是的,您可能正在https站点中使用不同的目录作为DocumentRoot
RewriteRule  (.*)  https://%{HTTP_HOST}/$1  [L]