Home > Net >  How to hit codeigniter API from an alias domain?
How to hit codeigniter API from an alias domain?

Time:04-23

I have a REST API project built in condeigniter 3 in www.mysiteone.com/project which works fine. Now, another domain of mine is www.mysitetwo.com/project is configured such way that it hits the first url. For example, if I browse www.mysitetwo.com/project/license.txt it shows the file that is in www.mysiteone.com/project/license.txt as it should. But the issue is when I am trying to access any of the APIs. Like www.mysiteone.com/project/apiendpoint returns data but when I am hitting www.mysitetwo.com/project/apiendpoint it is showing the following error:

<html>

<head>
    <title>404 Not Found</title>
</head>

<body>
    <h1>Not Found</h1>
    <p>The requested URL /srv/www/mysiteone.com/www/project/index.php/apiendpoint was not found on this server.
    </p>
</body>

</html>

here is the .htaccess file inside the project folder

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

And in config.php

$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';

Where should I make change to make this work?

CodePudding user response:

Need to replace

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

With

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

CodePudding user response:

Below will be more effective so as to handle possible future scenarios.

RewriteEngine on
RewriteCond "%{HTTP_HOST}"    "!^www\.mysitetwo\.com" [NC]
RewriteCond "%{HTTP_HOST}"    "!^$"
RewriteRule "^/?(.*)"         "http://www.mysiteone.com/$1" [L,R,NE]
  • Related