一直在寻找答案,但没有找到任何回复可以解决我的问题。 我正在使用以下.htaccess文件将用户从站点重定向到其https版本:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} !=on
# This checks to make sure the connection is not already HTTPS
# RewriteCond %{REQUEST_URI} !^/api-vop/
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
# This rule will redirect users from their original location, to the same location but using HTTPS.
# i.e. http://www.example.com/foo/ to https://www.example.com/foo/
# The leading slash is made optional so that this will work either in httpd.conf
# or .htaccess context
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
我首先要重定向到HTTPS,然后重写经典网址重写规则,将myfile.php等网址替换为/ my-file
我需要让一个http://my-server.com/api-vop的网址通过,而不会被重定向到https,如下所示:
# RewriteCond %{REQUEST_URI} !^/api-vop/
事情是我无法让它工作,充其量我回到index.php页面。
任何解决方案?
提前致谢!
答案 0 :(得分:0)
将您的第一条规则保留为:
RewriteCond %{HTTPS} off
# This checks to make sure the connection is not already HTTPS
# RewriteCond %{THE_REQUEST} !\s/+api-vop/
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L,NE]
THE_REQUEST
变量表示Apache从您的浏览器收到的原始请求,并且在执行某些重写规则后不会被覆盖。此变量的示例值为GET /index.php?id=123 HTTP/1.1