htaccess IP to HTTPS redirection on a domain with a special rewrite mod exists

45 Views Asked by At

I want to redirect the IP to a domain but the issue that there is an already Rewritecond & RewriteRule exists in the .htaccess and couldn't merge them together :

My .htaccess

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

To redirect IP to domain

RewriteEngine On
RewriteCond %{HTTP_HOST} ^50\.50\.60\.60
RewriteRule (.*) https://www.example.com/$1 [R=301,L]

This how it's working now :

From

http://example.com/

to

https://www.example.com/en/

The Whole issue is the with

/en/

It connects to Language.php on every URL and adds /en/

$config['default_language'] = 'en';

No idea how it's possible to merge this together i have tried lot of methods but noone worked.

This File is MY_Lang.php that selects the language from Language.php and adds it to the URL

function __construct()
    {
        parent::__construct();
        global $CFG;
        global $URI;
        require_once APPPATH . "config/language.php";
        $this->supported_languages = array_key_exists('supported_languages', $config) && !empty($config['supported_languages']) ? $config['supported_languages'] : $this->supported_languages;
        $this->current_language = array_key_exists('default_language', $config) && !empty($config['default_language']) ? $config['default_language'] : $this->current_language;
        $this->detect_language = array_key_exists('detect_language', $config) ? $config['detect_language'] : $this->detect_language;
        $this->default_uri = array_key_exists('default_uri', $config) ? $config['default_uri'] : $this->default_uri;
        $this->special_uris = array_key_exists('special_uris', $config) ? $config['special_uris'] : $this->special_uris;
        $this->uri = $URI->uri_string();
        $uri_segment = $this->get_uri_lang($this->uri);
        $this->lang_code = $uri_segment['lang'];
        $url_ok = FALSE;
        if((!empty($this->lang_code)) && (array_key_exists($this->lang_code, $this->supported_languages)))
        {
            $language = $this->supported_languages[$this->lang_code]['folder'];
            $CFG->set_item('language', $language);
            $this->current_language = $this->lang_code;
            $url_ok = TRUE;
        }
        if((!$url_ok) && (!$this->is_special($uri_segment['parts'][0]))) // special URI -> no redirect
        {
            // set default language
            $this->current_language = $this->default_lang();
            $CFG->set_item('language', $this->supported_languages[$this->current_language]['folder']);
            $uri = (!empty($this->uri)) ? $this->uri : $this->default_uri;
            $uri = ($uri[0] != '/') ? '/' . $uri : $uri;
            $new_url = $CFG->config['base_url'] . $this->default_lang() . $uri;
            header("Location: " . $new_url, TRUE, 302);
            exit;
        }
    }
0

There are 0 best solutions below