【问题标题】:htaccess force SSL breaks other ruleshtaccess force SSL 打破了其他规则
【发布时间】:2015-02-15 08:58:09
【问题描述】:

我正在尝试强制 SSL 并将每个人从 WWW 重定向到非 WWW(作为其子域),但我还有其他规则,用于漂亮的 URL...如果我删除强制 SSL 的代码,有用。如果它在那里,那么我的好网址不起作用(点击新闻只会打开 news.php 等)。

工作中 .htaccess(无强制 SSL):

Options +FollowSymlinks
RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.sub\.domain\.sk)$ [NC]
RewriteRule .* https://sub.domain.sk%{REQUEST_URI} [L,R=301]
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]

RewriteRule ^news$ /news.php [L]
RewriteRule ^contact$ /contact.php [L]
....
....

不起作用

Options +FollowSymlinks
RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.sub\.domain\.sk)$ [NC]
RewriteRule .* https://sub.domain.sk%{REQUEST_URI} [L,R=301]

RewriteCond %{ENV:REDIRECT_STATUS} 200 # If I delete this, I got infinite redirect
RewriteCond %{HTTPS} !=on
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]

RewriteRule ^news$ /news.php [L]
RewriteRule ^contact$ /contact.php [L]
....
....

我也试过这个(不工作):

Options +FollowSymlinks
RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.sub\.domain\.sk)$ [NC]
RewriteCond %{HTTPS} !=on
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]

RewriteRule ^news$ /news.php [L]
RewriteRule ^contact$ /contact.php [L]
....
....

感谢您的帮助。

Ps.:我找到了这个:.htaccess https breaks rewrite rules 但他们从来没有解决它,因为他们开始聊天......嗯。

【问题讨论】:

    标签: php apache .htaccess mod-rewrite ssl


    【解决方案1】:

    天哪。每次我问一些问题时,我都会在几分钟内尝试更多的东西来找到答案......

    无论如何,这段代码对我有用:

    Options +FollowSymlinks
    RewriteEngine On
    
    RewriteCond %{SERVER_PORT} 80 [OR]
    RewriteCond %{HTTP_HOST} ^www\.
    RewriteRule .* https://sub.domain.sk%{REQUEST_URI} [L,R=301]
    RewriteCond %{ENV:REDIRECT_STATUS} 200
    RewriteRule .* - [L]
    
    RewriteRule ^news$ /news.php [L]
    RewriteRule ^contact$ /contact.php [L]
    

    【讨论】:

    • 这不会删除www
    猜你喜欢
    • 2013-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多