【发布时间】:2014-07-22 16:07:07
【问题描述】:
而不是在核心 PHP 中,htaccess 的修改是不同的。 所以,经过一番搜索,我得到了以下代码。
在那之前, 我的要求在我的项目中是标准的。
- 严禁在整个站点中使用 www。即直接重定向到非 www 版本。
- HTTPS 适用于某些页面。 (结帐,登录页面)。其他页面严格使用 HTTP。
- 移除 CodeIgniter 的默认 index.php
这是我的代码。
RewriteEngine on
#################################
# force HTTPS
RewriteCond %{HTTPS} =off
RewriteCond %{REQUEST_URI} (checkout|login)
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# force HTTP
RewriteCond %{HTTPS} =on
#RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteCond %{REQUEST_URI} !(checkout|login|css|img|js)
RewriteRule .* http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Strict to non-www version >>> Not Working
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1%{REQUEST_URI}/$1 [R=301,NE,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [L]
问题:无法访问非 www 版本的网站的结果
更新(10 月 17 日)
# Strict to non-www version.
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteCond %{REQUEST_URI} (login|account_detail|alternate_address|update_password)
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L,QSA]
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteCond %{REQUEST_URI} !(login|account_detail|alternate_address|update_password|https|css|img|js|resources|images)
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L,QSA]
# force HTTPS
RewriteCond %{HTTPS} =off
RewriteCond %{REQUEST_URI} (login|account_detail|alternate_address|update_password)
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# force HTTP
RewriteCond %{HTTPS} =on
RewriteCond %{REQUEST_URI} !(login|account_detail|alternate_address|update_password|https|css|img|js|resources|images)
RewriteRule .* http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [L]
在这个新的更新代码上,htaccess 测试器站点完美地显示了所有内容。 但是,更新到网站后,有很多问题。
当我打开这个链接
https://example.com/login
它一直在循环,而不是停止。 在这个链接上 http://www.example.com/login 它重定向到
https://login/login
【问题讨论】:
-
试试
RewriteRule ^(.*)$ http://%1/$1 [R=301,L,QSA] -
兄弟你能详细说明一下,我在哪里可以添加这一行,或者我应该用什么替换,因为你给的建议我以前试过但没有奏效。这就像我缺少一些行或缺少一些排序。
-
而不是
RewriteRule ^(.*)$ http://%1%{REQUEST_URI}/$1 [R=301,NE,L] -
不。它不会从链接中删除 www。
-
您的 .htaccess 在哪里 - 在某个文件夹或网站的根目录中?如果在根目录中,则问题出在其他地方,因为我编写的规则有效。你可以在这里试试,例如htaccess.madewithlove.be为重写规则启用日志记录并查看日志。
标签: php apache .htaccess codeigniter