2016-01-04 88 views
8

點#1 如果鍵入:如何HTTP重定向到https的笨

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] 
+0

這集'$路線[ '404_override'] = '';' –

+0

已經set.but同樣的問題occure –

+0

和設置您的htaccess太 –

回答

2

現在,我得到一個解決方案,我 更新我的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] 

現在,它爲我工作順利.. :)

10

請檢查這可能會幫助

配置更改: - 轉到「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' 
           ); 

現在創建一個新的目錄名爲「鉤‘在‘應用程序/鉤/ 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()); 
    } 
} 
+0

鉤子是一個不錯的方法,而不是htaccess。 –

+0

你可以提供一些論據,爲什麼使用這個PHP實踐是比htaccess更好的方法?他們每次運行都檢查一定的規則 – Nebulosar

0

是確實這個

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] 

的作品,但你必須做一個輕微的編輯。在 codeiginiterfolder/application/config.php文件中將http替換爲https

另外,上面的代碼中的基礎網址,您必須將myhost替換爲您的主機名。假設我的主機名internetseekho.com因此而不是myhost您確實已寫internetseekho

0

對於我以上答案沒有工作,因爲它顯示我太多的重定向,但這個工作像魅力。因此,我認爲,如果別人進入類似的問題分享到:「?」

RewriteEngine on 

RewriteCond %{HTTPS} off 
RewriteCond %{REQUEST_URI} (sale|success|cancel) [NC] 
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 

RewriteCond %{HTTPS} on 
RewriteCond %{REQUEST_URI} !(static|sale|success|cancel) [NC] 
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 

RewriteCond $1 !^(index\.php|resources|robots\.txt|static) [NC] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php/$1 [L,QSA] 
0

如果您發現錯誤「未指定輸入文件」再加入 在最後一行

RewriteRule ^(。*)$ index.php /?$ 1從回答[L]

@asiya汗

0

首先去的application/config/config.php文件,尋找這一行:

$config['base_url'] = ""; 

將其設置用你的網址加上例如https https://example.com

$config['base_url'] = "https://example.com"; 

然後轉到您的.htaccess文件,並在下面給出的例子加入這一行。

重寫規則^(。*)$ https://example.com/ $ 1 [R,L]

<IfModule mod_rewrite.c> 

    #Options +FollowSymLinks 
    #Options -Indexes 
    RewriteEngine on 

    # Send request via index.php 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.*)$ index.php/$1 [L] 
    RewriteRule ^(.*)$ https://example.com/$1 [R,L] 


</IfModule> 
1

我試過上述所有的人,但他們沒有我的情況下正常工作。我發現下面的解決方案,它適用於我的情況。我希望它也會對你有所幫助。

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]