点#1 如果我键入:
www.myurl.com/somepage http://www.myurl.com/somepage http://myurl.com/somepage https://myurl.com/somepage
让它重定向到
https://www.myurl.com/somepage
第2点
When I type in something like www.myurl.com it is redirecting to https://www.myurl.com/index.php. Make it so the index.php is not displaying. It should just display https://www.myurl.com
来自评论htaccess
RewriteEngine On RewriteCond %{HTTP_HOST} ^myhost\.com$ [NC] RewriteRule ^(.*)$ myhost.com/$1 [R=301,L] RewriteCond %{THE_REQUEST} ^[A-Z]+\ /index\.php(/[^\ ]*)?\ HTTP/ RewriteRule ^index\.php(/(.*))?$ myhost.com/$2 [R=301,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L]
Preetham Heg.. 22
请检查这可能会有所帮助
配置更改: - 转到"application/config/config.php"并启用或设置挂钩为true.
$config['enable_hooks'] = TRUE;
在"application/config/hooks.php"中创建一个名为hooks.php的新文件,并在hooks.php中添加以下代码: -
$hook['post_controller_constructor'][] = array( 'function' => 'redirect_ssl', 'filename' => 'ssl.php', 'filepath' => 'hooks' );
现在在应用程序目录下创建一个名为"hooks"的新目录,然后在"application/hooks/ssl.php"中创建名为"ssl.php"的新文件,并将下面的代码添加到"ssl.php": -
function redirect_ssl() { $CI =& get_instance(); $class = $CI->router->fetch_class(); $exclude = array('client'); // add more controller name to exclude ssl. if(!in_array($class,$exclude)) { // redirecting to ssl. $CI->config->config['base_url'] = str_replace('http://', 'https://', $CI->config->config['base_url']); if ($_SERVER['SERVER_PORT'] != 443) redirect($CI->uri->uri_string()); } else { // redirecting with no ssl. $CI->config->config['base_url'] = str_replace('https://', 'http://', $CI->config->config['base_url']); if ($_SERVER['SERVER_PORT'] == 443) redirect($CI->uri->uri_string()); } }
钩子是一个很好的方法而不是htaccess. (2认同)
小智.. 12
我尝试了所有的但是在我的情况下它们没有正常工作.我发现下面的解决方案,它适用于我的情况.我希望它对你也有帮助.
RewriteEngine on RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] RewriteCond $1 !^(index\.php|resources|robots\.txt|public) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
asiya khan.. 6
现在我有了解决方案,我更新了htaccess文件。--
RewriteEngine On RewriteCond %{HTTPS} off [OR] RewriteCond %{HTTP_HOST} !^www\. [OR] RewriteCond %{HTTP_HOST} ^myhost\.com$ [NC] RewriteRule ^ https://www.myhost.com%{REQUEST_URI} [R=301,L,NE] RewriteCond %{THE_REQUEST} ^[A-Z]+\ /index\.php(/[^\ ]*)?\ HTTP/ RewriteRule ^index\.php(/(.*))?$ myhost.com/$2 [R=301,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L]
现在,它为我工作顺利.. :)
请检查这可能会有所帮助
配置更改: - 转到"application/config/config.php"并启用或设置挂钩为true.
$config['enable_hooks'] = TRUE;
在"application/config/hooks.php"中创建一个名为hooks.php的新文件,并在hooks.php中添加以下代码: -
$hook['post_controller_constructor'][] = array( 'function' => 'redirect_ssl', 'filename' => 'ssl.php', 'filepath' => 'hooks' );
现在在应用程序目录下创建一个名为"hooks"的新目录,然后在"application/hooks/ssl.php"中创建名为"ssl.php"的新文件,并将下面的代码添加到"ssl.php": -
function redirect_ssl() { $CI =& get_instance(); $class = $CI->router->fetch_class(); $exclude = array('client'); // add more controller name to exclude ssl. if(!in_array($class,$exclude)) { // redirecting to ssl. $CI->config->config['base_url'] = str_replace('http://', 'https://', $CI->config->config['base_url']); if ($_SERVER['SERVER_PORT'] != 443) redirect($CI->uri->uri_string()); } else { // redirecting with no ssl. $CI->config->config['base_url'] = str_replace('https://', 'http://', $CI->config->config['base_url']); if ($_SERVER['SERVER_PORT'] == 443) redirect($CI->uri->uri_string()); } }
我尝试了所有的但是在我的情况下它们没有正常工作.我发现下面的解决方案,它适用于我的情况.我希望它对你也有帮助.
RewriteEngine on RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] RewriteCond $1 !^(index\.php|resources|robots\.txt|public) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
现在我有了解决方案,我更新了htaccess文件。--
RewriteEngine On RewriteCond %{HTTPS} off [OR] RewriteCond %{HTTP_HOST} !^www\. [OR] RewriteCond %{HTTP_HOST} ^myhost\.com$ [NC] RewriteRule ^ https://www.myhost.com%{REQUEST_URI} [R=301,L,NE] RewriteCond %{THE_REQUEST} ^[A-Z]+\ /index\.php(/[^\ ]*)?\ HTTP/ RewriteRule ^index\.php(/(.*))?$ myhost.com/$2 [R=301,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L]
现在,它为我工作顺利.. :)