我正在尝试强制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但他们从未解决过,因为他们开始聊天......嗯。
答案 0 :(得分:0)
OMG。每当我问一些问题时,我会在几分钟内尝试更多的东西找到答案......
无论如何,这段代码对我有用:
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]