I have deployed my site on a VPN server. I am able to access the controller constructor, but when I am trying to call any method like mydomain/controller/method, it is not working. However 'mydomain/controller/index' is also not working.
When I am debugging with php method function_exists('my function name') then also it is coming up false even though that method exist in my controller.
Please help with this problem, and let me know if I have to do any config changes.
Thanks!
You will need to navigate to http://mydomain/index.php/controller/method
... unless you specifically have a .htaccess file in the root where index.php is that eliminates index.php from the URL.
If you have this .htaccess file set correctly you will be able to navigate to http://mydomain/controller/method
here is an example of an .htaccess file for codeigniter that I'm using for debugging.
php_flag display_errors on
php_value error_reporting 7
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
copy all of this text to a file called .htaccess and put it where index.php is in the codeigniter root directory.
///////////////// Edit based on more info from OP //////////////////
First test to see if the following works..
Unless you deleted it, CI provides you, by default a welcome controller (/application/controllers/welcome.php) and a welcome view thats being called by the controller (/application/views/welcome_message.php).
See if these files are there and if they aren't get them from the zip file in the codeigniter framework and put it in these directories.
navigate to the config folder and open routes.php (/application/config/routes.php) and under reserved routes put in $route['default_controller'] = "welcome"; if it's not already there.
In addition make sure you have the Config changed to reflect the fact that you are using the .htaccess file.
the property should be set as follows in config.php $config['index_page'] = '';
Note that if you are not using .htaccess this would be set to $config['index_page'] = 'index.php';
These instructions are in an effort to get you to see something on the page. You would change the default controller to your controller (not welcome) when you get going with the above.
Related
I downloaded a codeigniter folder from its official website. Setup it in wamp.
I remove index.php by making setting in .htaccess file.
'I left blank base url in config.'
Now, when i click on link to go to another controller, instead of showing http://localhost/projectname/cntrlname url is http://127.0.0.1/projectname/cntrlname.
I dont want to set base url. so, what should i do to make it work properly.
if you want to run your project without define base_url in config.php file.
You must keep some points in your mind.
1- Define base url as blank in config.php file.
$config['base_url'] = '';
2- You also leave index_page as blank in config.php file.
$config['index_page'] = '';
3- You must load helper url in autoload.php file, which is define in config folder.
$autoload['helper'] = array('url');
4- Suppose your project folder name test. then i write htaccess for that project for example.
RewriteEngine on
RewriteBase /test/
RewriteCond $1 !^(index\.php|cache|images|js|css|fonts|robots\.txt)
RewriteRule ^(.*)$ /test/index.php/$1 [L]
So, I have the current file structure:
ROOT
-> /public
-> /user_views
user_handle.php
user_profile.php
user_feed.php
user_settings.php
.htaccess
As you see, the folder user_views contains a few of the possible views that the client could want to look at. What I am wanting, is for clients that insert the URL http://example.com/user/ to be directed to the page user_handle.php. This handle would act as a root file for all /user/ pages, and it would accordingly split into those pages through numerous $_GET requests.
So far, I have the following .htaccess, but it's not working...
RewriteRule ^user/ user_views/user_handle.php [L]
What could I do to get this to work, so that the url http://example.com/user redirects to the user_handle file in the user_views folder?
Thanks!
I'm not sure I fully understand your question, but it seems you would like to make user_handle.php located under public/user_views act as a "router" for the rest of you PHP files and have all requests to /user/ (e.g. /user/?page=1) be processed by user_handle.php.
If that's the case, your rule seems legit. The only thing I noticed (I might be wrong) is that your .htaccess is located outside the public folder. In that's the case, you need to include 'public/' as part of your rule.
I recreated the folder/file structure you described and it has worked for me using the following .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^user/ public/user_views/user_handle.php [L]
</IfModule>
Slight chance this is the problem, but you also might want to double check that mod_rewrite, which is the rule-based rewriting engine is enabled on your server/local environment. It should show up under 'Loaded modules' when you call phpinfo() in any PHP file.
Hope this helps.
I have been using code igniter as a subdirectory of a site and have several instances of if on one server. Each instance is considered a separate application, but all under the same domain name. I am looking to enable a slightly different URL structure though and have turned to mod_rewrite to help me out.
The page is reachable at http://localhost/test but I want to rewrite that URL to appear as http://localhost/en-US/test.
The problem is I keep getting a code igniter (CI) 404. I can confirm the mod_rewrite is reaching the CI index.php, but CI is failing to deliver the correct page. Here's and example setup:
1) Download a new instance of CI and place it in a subdirectory in the site root. Name the CI folder "test". It should be reachable now on a local server at http://localhost/test and you should see the default welcome view.
2) Create a .htaccess file in the server's root web directory. DO NOT place it in the CI "test" directory. Add the following lines to it.
RewriteEngine On
RewriteBase /
RewriteRule ^en-US/test/?$ test/index.php [NC,L]
From my understanding of mod_rewrite, this should allow the URL http://localhost/en-US/test to render what is located at http://localhost/test. It doesn't though. I just get the CI version of a 404. I need help figuring out how to resolve this.
Hmm your question made me install CodeIgnoter and read its routing :)
Anyway have your DocumentRoot/.htaccess like this:
RewriteEngine On
RewriteBase /
RewriteRule ^en-US/(test)/(.*)$ $1/$2 [NC,L]
Then replace this line in your /test/application/config/config.php`:
$config['uri_protocol'] = 'PATH_INFO';
It is by default set to:
$config['uri_protocol'] = 'AUTO';
After this you can open this URL: http://domain.comen-US/test/ to load CI home page in /test/ dir.
You should check out routing. Place this statement in your config/routes.php file AFTER the reserved routs.
$route['test'] = "en-US/test";
You can forget about htaccess when you have Codeigniter (most of the times).
I recently uploaded my codeigniter project onto my web server.
it's in a folder called project1 this is what my directory view looks like
[www.myurl.com]
|-> project1
|-> application
|-> css
|-> images
|-> js
I am having two problems.
The first is that I want it to load my welcome view when I go to (www.myurl.com) and not
(www.myurl.com/project1/main_controller/index.php/welcome). How do i get rid of all that garbage?
The second problem is when I use <?php echo base_url();?> it shows up fine in view source but when I click on it, it echo's the url [www.myurl.com/project1/www.myurl.com/project1/] why is it doing this?
It looks like you've installed CodeIgniter into a subdirectory. If you want your CI site to load from the root url, you should copy it one directory up so the Application & System folders are directly under the root url of your web directory. From there, the .htaccess rules that are posted by shail (and quoted below) should take care of removing the index.php in your paths.
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ ci/index.php/$1 [L]
Regarding the site_url() issue, make sure you have your $config['base_url'] variable set in application/config/config.php and that it contains the trailing slash.
$config['base_url'] = "http://www.myurl.com/";
To test this further, try passing a parameter to the site_url() function like this:
echo site_url(welcome);
Which should return: http://www.myurl.com/welcome if everything is set right.
Getting CI up and running is rather simple. Most of it requires you to edit a few configuration
files.
You need to setup CI to point to the right base URL of the app. To do this, open up system/application/config/config.php and
edit the base_url array item to point to your server and CI folder.
view plaincopy to clipboardprint?
$config['base_url'] = "http://localhost/ci/";
Currently, the CI setup will have a default controller called “welcome.php”; you can find this in the system/application/controllers folder. For this tutorial, delete it and open your system/application/config/routes.php file. Change the default array item to point to the “helloworld” controller.
view plaincopy to clipboardprint?
$route['default_controller'] = "Helloworld"
CI also has a view file that we do not need. Open up the system/application/view/ folder
and delete the welcome_message.php file.
You can change your default controller here.
In order to edit Url http://localhost/ci/index.php/helloworld/.There are a few things you can do to improve your CodeIgniter experience -
like removing that annoying index.php bit out of the URL. You can accomplish this task by creating a .htaccess file in the root folder, and adding the following code.
RewriteEngine on
RewriteCond $1 !^(index.php|images|robots.txt)
RewriteRule ^(.*)$ ci/index.php/$1 [L]
You’ll also need to open up the config.php file in system/application/config/ and edit the index_page array item to a blank string.
view plaincopy to clipboardprint?
$config['index_page'] = "";
Another nifty trick is to turn on CI’s ability to parse PHP alternative syntax if its
not enabled by the server. To do this, open up the same file as before, system/application/config/config.php, and set the rewrite_short_tags array item to TRUE.
view plaincopy to clipboardprint?
$config['rewrite_short_tags'] = TRUE;
I hope all goes well!
I have set up a virtual host in my local machine (assume it to be http://local.he). I have a home.php in the main ‘controllers’ folder. I have two subfolders inside the ‘controllers’ folder and they are ‘admin’ and ‘wori’ and each has a home.php file.
Per CI 2.0 structure, if I access http://local.he/module/wori then it should load home.php from ‘wori’ and it is working but when I did the same in the server after uploading the files it always loads from module. Even if I access something like this: http://site.com/module/wori/users, it is still loading the home.php from module.
Here is the .htaccess
RewriteEngine on
RewriteCond $1 !^(index\.php|images|js|css|static)
RewriteRule ^(.*)$ index.php/$1 [L]
Here is the routing and these two are the only executable lines in routes.php
$route['default_controller'] = "home";
$route['404_override'] = '';
When I try to access http://site.com/module/index.php/wori or http://site.com/module/index.php/wori/users then it works. I checked .htaccess and it is working for other modules in my site. I even tried this example: CodeIgniter default controller in a sub directory not working but this is still not working:
$route['wori'] = 'wori/home';
Can anyone tell me what is missing?
I followed the answer from the following url and it worked for me.
http://codeigniter.com/forums/viewthread/181149/#857629
yet would like to know why it was working normally like in the localhost.