我正在学习 Apache .htaccess 配置。如果域仅为 mydomain.com,我想将 https 应用于 URL
如果 URI 以 API 开头并后跟数字
示例-->“http://exampledomain.com/api/123456”被重定向到后端服务器中的https://exampledomain.com/index.php?val=123456。
我已经尝试了以下但它不起作用。我也无法获得 API 链接以正确重写。任何帮助将不胜感激。
RewriteEngine On
RewriteRule ^api/([0-9]+) index.php?val=$1 [NC,L]
RewriteCond %{HTTP_HOST} ~exampledomain.com [NC]
RewriteRule (.*) https://%{HTTP_HOST}$1 [R,NC]
最佳答案
您能否尝试使用所示示例进行以下,编写和测试。您已接近尝试将 https 重定向规则首先放在规则文件的开头,然后继续进行。
RewriteEngine ON
RewriteCond %{HTTPS} !on
RewriteCond %{HTTP_HOST} ^(exampledomain\.com) [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,NE,L]
RewriteRule ^api/(\d+)/?$ index.php?val=$1 [NC,L]
关于apache - 无法在 Apache htaccess 中重写和重定向 API URI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65869511/