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
无法在Apache htaccess中重写和重定向API URI_Apache_.htaccess_Redirect_Mod Rewrite_Url Rewriting - Fatal编程技术网

无法在Apache htaccess中重写和重定向API URI

无法在Apache htaccess中重写和重定向API URI,apache,.htaccess,redirect,mod-rewrite,url-rewriting,Apache,.htaccess,Redirect,Mod Rewrite,Url Rewriting,我正在学习Apache.htaccess配置。如果域仅为mydomain.com,我想将https应用于URL 如果URI从API开始,后跟数字 例如-->”http://exampledomain.com/api/123456“要在后端服务器中重定向到 我试过下面的方法,但不起作用。我还没能让API链接正确重写。任何帮助都将不胜感激 RewriteEngine On RewriteRule ^api/([0-9]+) index.php?val=$1 [NC,L] RewriteCond %

我正在学习Apache.htaccess配置。如果域仅为mydomain.com,我想将https应用于URL 如果URI从API开始,后跟数字 例如-->”http://exampledomain.com/api/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]