带有.htaccess的HTTPS和REST API
首先,我在apache2服务器上使用以下带有.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
.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
myfoldersites enabled
运行时,包含了一个新文件sites enabled/default ssl
。在这个文件中,我必须设置
AllowOverride All
就像我已经在使用httphttp
时对上所做的那样。我补充说,.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]