【发布时间】:2014-12-13 21:14:42
【问题描述】:
首先,我使用以下.htaccess 文件在 apache2 服务器上为我的 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>
效果很好。如果我输入例如http://mypage.de/REST/SomeRule/12我的index.php在文件夹REST/收到信息SomeRule/12。
现在我在我的服务器上启用了SSL,我想强制 API 使用https,所以我将以下代码添加到我的.htaccess 文件中:
RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://%{HTTP_HOST}/$1 [L]
现在我收到一个找不到页面的错误。您能在.htaccess 文件中看到错误,还是必须在其他地方?我对这些文件不是很熟悉。为了创建我的 API,我使用了 this tutorial。
【问题讨论】:
-
可以直接使用
https://domain.com/REST/SomeRule/12URL访问API吗? -
这个也没试过。所以也许它不适用于我的api。就像我说的,我按照问题中链接的教程进行操作。
-
如果您也使用
https://domain.com/REST/SomeRule/12得到 404,那么您可能没有正确设置 SSL 站点。为 https 站点提供VirtualHost配置 -
所以对于
https://domain.com/REST/SomeRule/12它说:The requested URL /REST/SomeRule/12 was not found on this server.似乎链接到 index.php 不起作用。 -
是的,您可能在 https 站点中使用不同的目录作为 DocumentRoot
标签: .htaccess rest ssl https apache2