使用.htaccess重定向除一个动态url之外的所有url

使用.htaccess重定向除一个动态url之外的所有url,.htaccess,redirect,.htaccess,Redirect,我想将所有url从http重定向到https,这对我来说很好 RewriteEngine On RewriteCond %{HTTPS} !=on RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -l [OR] RewriteCond %{REQUEST_FILENAME} -d Re

我想将所有url从
http
重定向到
https
,这对我来说很好

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
现在我想在此规则中添加一个例外,即每当用户请求以下动态url(最后一个字符串是动态生成的)时,它不应该应用force
https
redirect

sub.domian.dev/api/v/1/download/zip/token/8397298347ksjdnkjasdn0394834 
我试过这个规则,但不起作用

#url to exclude
RewriteCond %{REQUEST_URI} !^/api/v/1$
有人能告诉我怎么做吗

谢谢。

您可以使用以下代码:

RewriteEngine On

# except /api/v/1/ requests redirect everything else to https
RewriteCond %{THE_REQUEST} !\s/+api/v/1/ [NC]
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteRule ^ index.php [L]
您可以使用:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/api/v/1/
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

谢谢,我不希望
/api/v/1/
成为强制http,用户应该能够使用
http
https
访问此URL。