.htaccess https 重定向问题

.htaccess https 重定向问题

我在 htaccess 中设置了一条指令,将所有非 https 流量发送到 https

RewriteCond %{SERVER_PORT} ^80$
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

# These are used by the Zend Framework...
RewriteCond %{REQUEST_FILENAME} \.(js|css|gif|jpg|png|swf)$ [OR] 
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

我现在需要添加两个例外来阻止它们被重定向到 https - 一个用于 mydomain.com/register/,一个用于 mydomain.com/services/test/

有人能帮助我吗?

谢谢。

答案1

好的,有人帮助我使用以下方法使其工作:

 RewriteEngine On

 RewriteCond %{SERVER_PORT} !^443$
 RewriteCond %{THE_REQUEST} !/services/test
 RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

 RewriteCond %{REQUEST_FILENAME} \.(js|css|gif|jpg|png|swf)$ [OR]
 RewriteCond %{REQUEST_FILENAME} -s [OR]
 RewriteCond %{REQUEST_FILENAME} -l [OR]
 RewriteCond %{REQUEST_FILENAME} -d
 RewriteRule ^.*$ - [NC,L]

 RewriteCond %{THE_REQUEST} /services/test
 RewriteRule ^.*$ index.php [NC,L]

 RewriteRule ^.*$ index.php [NC,L]

Zend Framework 重写规则导致了一个问题,但现在运行正常。

答案2

RewriteCond %{SERVER_PORT} ^80$
RewriteCond %{REQUEST_URI} !^mydomain.com/register/$
RewriteCond %{REQUEST_URI} !^mydomain.com/services/test/$
RewriteRule .*https://%{服务器名称}%{请求URI} [R,L]

答案3

仅当 URL 不符合以下两个例外情况时,您才可以进行重写:

RewriteCond %{SERVER_PORT} ^80$
RewriteRule !^http://mydomain.com/(register|services/test).*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

相关内容