htaccess重定向到http特定网址和除http之外的所有网址

时间:2014-12-29 13:13:47

标签: php apache .htaccess redirect

我正在尝试将特定网址重定向到https以及http上的所有其他网址但不能正常工作。

httphttps条件工作正常,但http部分的https网址不能正常工作

我读了多个答案而不是多个[OR]条件!^(login|brandcontroller|...)已将https应用于http但未正常工作

     #HTTPS:// --> to --> HTTP:// (all url except https urls)
    RewriteCond %{HTTPS} on
    RewriteCond %{REQUEST_URI} !^(login|brandcontroller|admin|archives|lightboxs|enquiries|uploaders|brandarchives|content) [NC] 
    RewriteRule . http://%{SERVER_NAME}%{REQUEST_URI} [L]

    #HTTP:// --> to --> HTTPS:// (specific urls)
    RewriteCond %{HTTPS} off
    RewriteCond %{REQUEST_URI} ^(login|brandcontroller|admin|archives|lightboxs|enquiries|uploaders|brandarchives|content) [NC]
    RewriteRule . https://%{SERVER_NAME}%{REQUEST_URI} [L]

任何人都可以帮助htaccess重定向

1 个答案:

答案 0 :(得分:0)

我找到了在htaccess文件中设置!= {{REQUEST_URI}}的方法

HTTP:// - >到 - > HTTPS://(特定网址)

RewriteCond %{HTTPS} off
# force https for all required URLs
RewriteCond %{REQUEST_URI} ^(?:login\/signin|forgot|brandcontroller|admin)
RewriteRule . https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

HTTPS:// - >到 - > HTTP://(所有家庭)

# do not do anything for already existing files
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .+ - [L]
# force http for all other URLs
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^(?:login\/signin|forgot|brandcontroller|admin)
RewriteRule .* http://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]