使用.htaccess我最近使用以下代码将我的所有网站http://请求重定向到https://:
Ship createShip(int startPos) {
Ship newShip;
newShip[0] = startPos;
// ... <- rest of your code that you have to populate
return newShip;
}
int main()
{
int pos;
cout << "Enter a coordinate (out of 100) for good ship: "<< endl;
cin >> pos;
Ship good = createShip(pos);
//...
//... <- Get pos of bad ship
Ship bad = createShip(pos);
}
301重定向正在运行,现在每个人都登陆https。但是,当用户使用http://的书签链接时,或者我发送一个格式为http://而不是https://的网址时,他们会使用与他们点击链接时不同的网址在网站上。
如果主页上的链接如下所示:https://www.example.com/rest_of_url
如果使用http(http://www.example.com/rest_of_url)向客户发送了一个链接,并点击了链接,则会加载:https://www.example.com/index.php?/rest_of_url
我曾尝试使用.htaccess和以下代码从URL字符串中删除index.php?/但是这样做无效:
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
任何阻止人们使用index.php登陆网址的建议都会很棒
请求这是整个htaccess文件: RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^GET.*index\.php\?/ [NC]
RewriteRule (.*?)index\.php\?/ / [R=301,NE,L]
答案 0 :(得分:1)
按顺序排列:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
确保在测试之前清除浏览器缓存。