2016-01-04 12 views
8

प्वाइंट # 1 अगर मैं टाइप करें:CodeIgniter में https करने के लिए http अनुप्रेषित कैसे

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

और भी –

उत्तर

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

कृपया इस चेक

मदद मिल सकती है

कॉन्फ़िगरेशन परिवर्तन: - "एप्लिकेशन/config/config.php" पर जाएं और हुक को सही या सक्षम करें।

$config['enable_hooks'] = TRUE; 

एक नया "आवेदन/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 pratice का उपयोग 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 फ़ाइल httphttps के साथ प्रतिस्थापित करें।

इसके अलावा, उपर्युक्त कोड में आधार यूआरएल आपको अपने होस्ट नाम पर 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

आप त्रुटि आती है तो "कोई इनपुट निर्दिष्ट फ़ाइल" तो जोड़ने पिछली पंक्ति में

रिवाइट्रूल^(। *) $ Index.php /?$ 1 से [एल]

जवाब में @asiya खान

0

पहले आवेदन/config/config.php फ़ाइल के पास जाकर इस लाइन के लिए देखो:

$config['base_url'] = ""; 

यह सेट https के साथ आपके यूआरएल में https://example.com

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

फिर अपने .htaccess फाइल करने के लिए जाने के लिए और नीचे दिए गए उदाहरण में इस लाइन को जोड़ने।

RewriteRule^(। *) $ https://example.com/ $ 1 [आर, एल]

<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] 
संबंधित मुद्दे