skip to Main Content

I’m using Codeigniter, now the rewrite is working fine for accessing using domain name, here is the default Codeigniter htaccess:

RewriteRule ^(.*)$ index.php?/$1 [L]

But I want to make it able to access using IP address as well and I host my website in a shared hosting with cPanel, so the IP address will be something like this: http://11.11.11.11/~username. But it just not working when I access using IP, I had tried adding a RewriteBase and also something like:

RewriteRule ^(.*)$ ~username/index.php?/$1 [L]

and

RewriteRule ^~username/(.*)$ index.php?/$1 [L]

but non of them work. Anyone please help? Thank you.

2

Answers


  1. Chosen as BEST ANSWER

    Ok I just found the solution, I should check the host so that RewriteBase only will work properly:

    RewriteCond %{HTTP_HOST} ^www.domain.com [NC]
    RewriteRule ^(.*)$ index.php?/$1 [L]
    
    RewriteBase /~username/
    RewriteCond %{HTTP_HOST} ^11.11.11.11 [NC]
    RewriteRule ^(.*)$ index.php?/$1 [L]
    

  2. Ping,

    Unfortunately, you can not use IP as host while you’r on shared hosting. Share hosting shared single IP for multiple websites.

    You need dedicated hosting or VPS for your purpose.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search