I am new to codeigniter frame work. I have installed CodeIgniter 2.1.4 version. I set up the application and system path in my local wamp server. The front end opens fine.
But when i try to open the admin i.e http://siteurl/CodeIgniter_2.1.4/admin
it shows as 404 not found. In application >> controllers >> admin.php is found (Hope this is for admin panel)
Then why it shows as 404 not found. Shall i made any setup for admin url? Please help me. Thanks
You will need multiple things in place in order to achieve this:
Set the $config['index_page'] to an empty string in application/config/config.php
You will have to rewrite the requests coming in, for example with apache you will need to have rewrite rules like this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1/ [L,QSA]
You can put them into a file called .htaccess next to the index.php (your webserver need to be configured to support these kind of files for this to work)
You will have to have a function called index inside your admin.php, inside a class called Admin.
Related
I've been working on my first MVC-Based PHP application recently, using the CodeIgniter Framework. The project is now ready to go live for my friend/user to evaluate. As per the documentation, I have set the base url to 'http://sitename.co.uk/subdir/'.
When I browse to http://sitename.co.uk/subdir I'm redirected to http://sitename.co.uk/sitename/subdir. My shared hosting has a parent directory containing children directories with the name of each site I am hosting. I believe this is perhaps the cause of this.
I have attempted modifying the .htaccess, on the off-chance that this was overwriting the base url defined in config.php, though this did not appear to be the case. The base_url in config.php appears to have no affect on where I'm redirected to when browsing to this page.
The line for the base url currently reads:
$config['base_url'] = 'http://sitename.co.uk/subdir/';
As always, any assistance is appreciated. I have little experience with web publishing.
Setting $config['base_url'] does not do any redirection check if you have .htaccess it should have this code
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
I'm new with codeigniter and right now I'm trying to migrate a codeigniter application to another server. This application was in another server and now I want to move it to another server. In this server I have also a wordpress website and it works perfectly.
Firstly, what I have done it's a backup from the mysql database and from the files and I have move them via ftp to the another server under the /inventarios folder, so if I wrote on my browser
http://xxxxxx.com/inventarios
I should see the codeigniter application but what I receive it's a 404 error with the Wordpress interface
I have change the database.php and the another files from the config folder and it doesn't work. Why?. Under the inventarios folder I don't have a .htaccess file. Could you help me,please?. Thanks and let me know if you need more details.
EDIT 01
The htaccess which I have in the root folder is this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I don't know if inside of inventarios I should place another htaccess.
Thanks so much
Create sub-folder with name of inventarios in root of your host. Inside the folder upload all your CI folders(application, system, index....).
Then go to application/config/config.php
$config['base_url'] = 'http://xxxxxx.com/inventarios';
Also /application/config/database.php is to be edited
application/config/config.php
application/config/database.php
Don't forget to update .htaccess in root if there're some updates or url redirects to old domain/url
Here is my views directory:
- views/
- home.php
- contact.php
- assets/
- css/
- main.css
config.php: (changing this doesn't seem to do anything)
$config['index_page'] = 'index.php';
routes.php:
$route['default_controller'] = "welcome";
When I request www.example.com/index.php, the default page (i.e. home.php) loads and all of the assets work. However, when I request www.example.com/index.php/welcome or www.example.com/index.php/welcome/index, the page loads but the assets don't work. The same also happens if I try to load the page from a link from the home page.
I have no idea what index.php is for. I want to be able to just request www.example.com/welcome/index which will call the welcome.php controller and call the index method. application/index.php looks pretty important for everything to work, do I haven't deleted it, but I don't really want it. What can I do?
Thanks.
I think you're asking 3 different questions here.
Firstly index.php is the main entry point for your codeigniter app. It's very important as all of your routes will go through the index. The reason you can change it in the config is so you can rename it to something other than index.php if your setup requires it
Secondly, just guessing here but I think your assets are being loaded using a relative path; prefix all of your assets with base_url(); e.g
<?=base_url();?>assets/css/style.css
Thirdly, you'll need a htaccess file to hide the index.php (to give you www.example.com/welcome), or the equivalent if you're not using an apache server, which will look like the below (taken from http://www.codeigniter.com/user_guide/general/urls.html:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
Enable mode Rewriting on your server LAMP/WAMP and add a .htaccess file with following code
RewriteEngine on
RewriteCond $1 !^(index.php|resources)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
after doing above process you can use your urls without index.php i.e like www.example.com/welcome/index as well as your assets directory www.example.com/assets
Before all learn How MVC framework will work,
www.example.com/controller/function
If you call www.example.com , then default controller will load. You can change this in config.php
Inside the function you can call view ( your actual html viewable scripts ). follow the user guide from https://ellislab.com/codeigniter/user-guide
by default codeignitor url will be like www.example.com/index.php/controller/function
index.php can be removed using .htaccess
I have created a login page using codeigniter framework.it works well.
After install apachi,mySql and php again my website login is not working.
I can go to "http://localhost/test/" and login button is there.
After The requested URL /test/user/user/login was not found on this server.When I click the login button redirect to the page "http://localhost/test/user/user/login" and it says "The requested URL /test/user/user/login was not found on this server"
How can I solve this?
It works well before I format the computer and install php again.
sloved after changing AllowOverride None to AllowOverride All in /etc/apache2/sites-enabled/000-default .
I have had a lot of problems trying to fix this issue and finally I have figured out that without changing index.php field within the config.php file, you have to specify the address like this; http://localhost/codeigniter_folder_name/index.php?/controller_name
This has solved it for me.
Your .htaccess file maybe inside the application folder. Move it outside the application folder, also ensure to re-write the .htaccess file as follows:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Why you have used user twice like http://localhost/test/user/user/login. Here, user is the name of the controller. So the url should be like http://localhost/test/user/login. If you are not using htaccess file ie, mod_rewrite is not enabled, then the url should be like http://localhost/test/index.php/user/login
I'm having a hardtime on this part. Well I created a login page using codeigniter wherein the whole path would be http://localhost/CodeIgniter_2.1.3/index.php will be rewritten into http://localhost/login using .htaccess. Well it works just fine but the problem is after I made a successful login and the page redirects to next page using redirect('next_page'); since the URL would be http://localhost/CodeIgniter_2.1.3/index.php/next_page instead of http://localhost/next_page. I also created a rewriterule for that part :
RewriteRule ^events$ /CodeIgniter_2.1.3/index.php/events [L,NC]
and whenever I key in the http://localhost/next_page in the addressbar the page would appear just fine (since I haven't applied any rules on login and on this page.) I also tried using redirect('http://localhost/events'); this also works just fine but still I know this is not the real solution for this. Oh by the way my .htaccess exists on the www folder of wampserver. Any way to solve this?
First of all your domain ROOT folder should be the codeigniter folder
forexample
c:/www/codeigniter_2.1.3/
just move the files from the codeigniter_2.1.3 to your root folder OR make the codeigniter folder ROOT.
Then use just normal .htaccess rewrite as:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php/$1 [L]
And use the Codeigniter ROUTER to make your pages as you want them
example:
$route['login'] = 'welcome/login';
Will set http://localhost/login page to be loaded from the Welcome controler Login function.
You can set $routes at your routes.php in the config folder.
P.S> If you want not to see index.php on each page check your Config/config.php for the index_page and make it blank.
You might just want to add virtual host to your localhost. here is one step by step explanation on how to do that.
now all you have to do is create an .htaccess file inside your CodeIgniter_2.1.3 folder that will remove only the index.php in the url.