Welcome Guest, Not a member yet? Register   Sign In
How to configure a copy of Codeigniter website on a subdomain?
#1

I want to create a testing environment for my working Codeigniter (version 3.1.9) website.
It should be an exact replica of my original website, where I can modify the code and test changes before uploading them to the real website.

I thought I'd do it using a subdomain on my main domain.

I set the subdomain (test.mydoaim.com) through cPanel, and copied all the code files to the relevant directory.

Now, when I go to test.mydomain.com, or to test.mydomain.com/controller_name, it all works well, but when I try any inner links (such as test.mydomain.com/controller_name/anything), I get nothing on Firefox, or this error message on Chrome:

Quote:This page isn’t working
www.test.mydomain.com is currently unable to handle this request.

I'm guessing this is an htaccess issue? or a routing issue?
Any pointers on how to make this work would be highly appreciated!

My config/routes.php file is quite simple:

PHP Code:
$route['default_controller'] = 'website';
$route['404_override'] = 'student/four_o_four';
$route['translate_uri_dashes'] = FALSE;
$route['demo'] = 'student/demo'

And this is my htacces file:
Code:
RewriteOptions inherit
RewriteEngine On

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

# for non www urls, add www and force https:
RewriteCond %{HTTP_HOST}(.*) !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R,L]

# BEGIN cPanel-generated php ini directives, do not edit
# Manual editing of this file may result in unexpected behavior.
# To make changes to this file, use the cPanel MultiPHP INI Editor (Home >> Software >> MultiPHP INI Editor)
# For more information, read our documentation (https://go.cpanel.net/EA4ModifyINI)
<IfModule php7_module>
  php_flag display_errors Off
  php_value max_execution_time 120
  php_value max_input_time 60
  php_value max_input_vars 1000
  php_value memory_limit 128M
  php_value post_max_size 8M
  php_value session.gc_maxlifetime 1440
  php_value session.save_path "/var/cpanel/php/sessions/ea-php70"
  php_value upload_max_filesize 32M
  php_flag zlib.output_compression Off
</IfModule>
<IfModule lsapi_module>
  php_flag display_errors Off
  php_value max_execution_time 120
  php_value max_input_time 60
  php_value max_input_vars 1000
  php_value memory_limit 128M
  php_value post_max_size 8M
  php_value session.gc_maxlifetime 1440
  php_value session.save_path "/var/cpanel/php/sessions/ea-php70"
  php_value upload_max_filesize 32M
  php_flag zlib.output_compression Off
</IfModule>
# END cPanel-generated php ini directives, do not edit
RewriteCond %{HTTP_HOST} ^olddomain\.co\.il$ [OR]
RewriteCond %{HTTP_HOST} ^www\.olddomain\.co\.il$
RewriteRule ^(.*)$ "https\:\/\/newdomain\.co\.il\/$1" [R=301,L]

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “alt-php70” package as the default “PHP” programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-alt-php70 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
Reply
#2

Hi,
imho, first thing to check, if you set your subdomain as test.domain.com, try to access... test.domain.com without the www which means: comment those two lines
<code>
RewriteCond %{HTTP_HOST}(.*) !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R,L]
</code>
in your htaccess file with an #

second thing i would suggest if this subdomain is a test one, but you may already have done this, create a dedicated db for the subdomain else whatever you change in the db will appear on the production domain too...

hope it helps
have a nice day
Reply
#3

Have you set $config['base_url'] to reflect the subdomain, e.g.

PHP Code:
$config['base_url'] = 'https://www.test.mydomain.com'
Reply
#4

(This post was last modified: 09-01-2019, 06:18 AM by einav.)

(09-01-2019, 05:09 AM)dave friend Wrote: Have you set $config['base_url'] to reflect the subdomain, e.g.

PHP Code:
$config['base_url'] = 'https://www.test.mydomain.com'

My base_url seems to be configured OK, since I am able to access  test.mydomain.com, or test.mydomain.com/controller_name.
Its only the inner pages, such as test.mydomain.com/controller_name/anything that cause an error.

This is how my base_url is configured, under config/config.php:
PHP Code:
$protocol is_https() ? "https://" "http://";
$host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : "";

if(
is_cli()){
  $config['base_url'] = '';
}

elseif(
stristr($host"localhost") !== FALSE || (stristr($host'192.168.') !== FALSE) || (stristr($host'10.0.2.2') !== FALSE)){
  $config['base_url'] = $protocol $host "/pi/";
}

else{
    $allowed_hosts = ['mydomain.tld''www.mydomain.tld','anotherdomain.tld','www.test.mydomain.tld'];

    $config['base_url'] = in_array($host$allowed_hosts) ? $protocol.$host."/" "we-do-not-recognise-this-host.com";


(09-01-2019, 03:30 AM)virtualgadjo Wrote: Hi,
imho, first thing to check, if you set your subdomain as test.domain.com, try to access... test.domain.com without the www which means: comment those two lines
<code>
RewriteCond %{HTTP_HOST}(.*) !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R,L]
</code>
in your htaccess file with an #

second thing i would suggest if this subdomain is a test one, but you may already have done this, create a dedicated db for the subdomain else whatever you change in the db will appear on the production domain too...

hope it helps
have a nice day
Hi,

I tried removing the www, and I narrowed my htaccess file to just:
Code:
[php]RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L][/php]


But the results are the same Sad 

And yes, I did set up a duplicate db for testing purposes. But that's a good pointer. I t would be a shame to mess up the real db!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB