我希望我的整个网站都在https下。所以我做了两件事:
1.我将config.php中的base_url更改为
https://localhost/codeignitor.
来自
http://localhost/codeignitor.
2.我改变了.htaccess文件:
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|codeignitor|include|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [QSA]
# The following two lines newly added
RewriteCond %{HTTPS} off # To redirect all the http to https
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301]
但是当我访问时
http://localhost/codeignitor/mysite
这是我的错误[虽然它被重定向到https]
Not Found
The requested URL /codeignitor/my_site was not found on this server.
但是
https://localhost/codeignitor/index.php/my_site
很好。
答案 0 :(得分:1)
似乎.htaccess未在您的https服务器配置中读取,并且您正在使用LAMP(Apache),因此请转到您的服务器配置位置以获取https,例如: default-ssl或httpd-ssl.conf,并确保启用AllowOverride。如果您没有该行,则需要添加该行。
<Directory /your/directory/to/codeigniter/>
AllowOverride all
</Directory>