I am using codeigniter to develop an application, everything is fine but I have stacked on how to specify the base_url in config.php, I have installed SSL, I need whatever visitor will type the link the ssl should work like this https://www.zoepoint.com, but what it do now is user should type the whole link as it is for SSL to work, i.e when you type www.zoepoint.com, it comes with no SSL, but also when you type the whole link https://www.zoepoint.com or https://zoepoint.com it works fine but other links on the website does not work.
Currently I have specified base_url = 'https://zoepoint.com/'
If Apache is your web server then add the code below to your .htaccess file. This code will force any request to use the https protocol.
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
try this
$base = "http://".$_SERVER['HTTP_HOST'];
$base .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
$config['base_url'] = $base;
hope this will work for you
Try This one
$base_url = "http://".$_SERVER['HTTP_HOST'];
$base_url .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
$config['base_url'] = $base_url;
Related
I have downloaded and using Codeigniter 3.1.11.
I have copied the same to as usual htdoc folder.
Tomcat is Binary Installed and service running and able to get
the Welcome page with http://localhost/CodeIgniter3111/index.php/welcome.
I have inserted in .htaccess as below.
RewriteEngine On
RewriteCond $1 !^(index\.php|assets|images|js|css uploads|fevicon.png)
RewriteCond %{HTTP_COOKIE} ais=([a-z0-9-_]+)
RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-f
RewriteBase /CodeIgniter3111/
RewriteRule ^(.*)$ ./index.php/$1 [L]
and also removed the index.php from Config.
$config['base_url'] = 'http://localhost/CodeIgniter3111'; and added the base url as well.
As I type in url (http://localhost/CodeIgniter3111/welcome), I am
getting below error in browser.
Not Found
The requested URL /CodeIgniter3111/welcome was not found on this server.
I appreciate support in advance.
$config['base_url'] = 'https://localhost:8888/Your folder name';
your port number should be there
The project locally works fine $config['base_url'] = "localhost/";
Codeigniter is getting the default controller welcome and login.php, but login.php is not getting the resources from assets folder
all the get requests for a resource are not found. When I inspect I get errors
xGET example.com/assets/TEMPLATE/LoginPage/vendor/bootstrap/css/bootstrap.min.css
net::ERR_ABORTED 404
CodeIgniter folder structure in Cpanel public_html
+application
+assets
+system
index.php
.htaccess
I've configured the application/config/config.php
$config['base_url'] = 'www.mysite.com/';
$config['index_page'] = '';
I've configured the application/config/autoload.php
$autoload['packages'] = array('url');
.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
the pages are loading resources:-
<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>assets/TEMPLATE/LoginPage/vendor/bootstrap/css/bootstrap.min.css">
Rather than using href="<?php echo base_url();?>assets/TEMPLATE/LoginPage/vendor/bootstrap/css/bootstrap.min.css"> just use href="/assets/TEMPLATE/LoginPage/vendor/bootstrap/css/bootstrap.min.css">
Also, add http:// or https:// to your base URL depending on your SSL status.
Try using link_tag from html helper.
First load html helper in controller, or make it autoload in config/autoload.php
$autoload['helper'] = array('html');
Then try putting this in your header block of view file:
<?php echo link_tag('assets/TEMPLATE/LoginPage/vendor/bootstrap/css/bootstrap.min.css') ?>
I have some form like this
<form action=<?php base_url('logincontroller/loginaction');?> method=post >
by using base_url as
$config['base_url']="localhost/testsite/index.php";
If I give like this it works just fine.
But I know it is not the correct way for giving base_url if i give base_url as.
$config['base_url']="localhost/testsite/";
Like this when i click submit it will come up with error that page not found
what should i do to get it work?
You need to change your .htaccess file in your project root folder. Here is the line that you need to add after RewriteEngine On:
RewriteRule ^(.*)$ index.php/$1 [L]
And also enable rewrite in your apache by issuing this command in terminal:
sudo a2enmod rewrite
Finally, restart your apache service by this command:
sudo service apache2 restart
and then check the 'url' helper enabled in autoload.php line no : 67 file in config folder
$autoload['helper'] = array('url');
I'm relatively new to CI and I'm wondering if anyone knows how to set the default page of CI. I just transferred my files from my local server to my remote server and am having some problems. Firstly, I think it's important to note that I edited the .htaccess file so that the index.php was removed from the URL.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Secondly, in my config.php file, I have:
$config['base_url'] = '';
$config['index_page'] = 'sportstream';
sportstream is the name of a controller that is found in the application/controllers/ folder. From my experiences without using CI (or any other framework), the index.php file inside of the public_html folder on the remote server is the one that is loaded by default upon visiting a site. But, with CI, whenever I try to visit my domain name, a 404 error is returned. I have tried setting to base_url to http://www.mysite.com without any luck.
Does anyone here know how to make it so that upon visiting http://www.mysite.com that http://www.mysite.com/sportstream will be loaded?
You need to add a RewriteBase in your .htaccess file:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
NOTE: I have added a ? after the index.php as well.
I would also set the follow to an empty string (after you have tried the above):
$config['base_url'] = '';
$config['index_page'] = '';
Finally, in your routes.php file:
$route['default_controller'] = 'sportstream';
Update
In application/config/database.php you need to change your database driver. On your localhost, MySQLi was the database driver set. On your remote server, however, MySQLi was not installed, so changing it to MySQL should fix the issue.
//old - works on local server
$db['default']['dbdriver'] = 'mysqli';
//new - works on remote server
$db['default']['dbdriver'] = 'mysql';
For some reason, Codeigniter just "breaks" and shows the blank screen with no errors.
You have to set default controller in $route['default_controller'] ="sportstream"; it is located in aplication/config/route.php, So when visitinghttp://www.mysite.com/thesportstream` controller will be loaded by default.
Check about default controller in User guide
Switch back the $config['index_page'] = '';
If you renamed the index.php then you must enter the index_page name in config or else you can keep it blank.
Recommended Codeigniter starter guide: http://net.tutsplus.com/tutorials/php/codeigniter-basics/
I build codeigniter project and i have tested it in my local machine using http://works.dev/rcsoft as base url. I upload that project to cpanel and my new url like http://testsomeone.org/rcsoft. Home page is working.
But it is not working for other controller page such as http://testsomeone.org/rcsoft/person. It is giving
Not Found
The requested URL /index.php/person was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
But it working for http://testsomeone.org/rcsoft/index.php/person
my .htaccess file
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
My config.php
$config['base_url'] = 'http://testsomeone.org/rcsoft/';
$config['index_page'] = '';
Please help me. What is the issue?
First open up application/config/config.php file and edit line #17 as the example below:
$config['base_url'] = 'http://testsomeone.org/rcsoft/';
Second, insert the following line right after RewriteEngine On in .htaccess file:
RewriteBase /rcsoft/
Is it working fine in your local machine?..if so then just change the details in routing file..then try ..