Base_url in CodeIgniter is not working - codeigniter

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');

Related

Laravel 404 error with xampp

I am starting to learn how to work with laravel but got a problem. When I go to: http://localhost/testing/public/ I get a working page but when I typ for example http://localhost/testing/public/home which is one of my views I get a 404 error. Does someone know how to fix this?
Edit:
I am using the latest version of laravel and when I do for example:
Route::view('/home', 'home');
In my routes/web.php I get that error
This is more likely a problem with virtual Hosts, try the following:
First edit your route to :Route::get('/home', function(){echo
"hello"});
Then try to access: http://localhost/testing/public/index.php/home
If it works then its certainly because you don't have a virtualHost, you can set it easily in your Xampp config and modifying ur hosts file
First go to C:\Windows\System32\drivers\etc\hosts and add a new
line like: 127.0.0.1 yoursite.local
Then go to where xampp is installed under
xampp\apache\conf\extra\httpd-vhosts.conf
Then add a virtual host in the bottom of the file like:
<VirtualHost *:80>
DocumentRoot "PATH_to_laravel_folder/public"
ServerName yoursite.local
</VirtualHost>
Then you can access your route by typing: yoursite.local/home or
yoursite.local:80/home
Hope it helps you guys :)
It may be because of routes.
after creating a view you have to add it in routes/web.php
like Route::view('/yourUrl', 'viewName'); in 5.5 version.
for 5.4 or older versions Route::get('/yourUrl', 'viewName');
after adding this to routes/web.php. you can access http://localhost/testing/public/yourUrl
you can find more here
If http://localhost/testing/public/index.php/home works, try to create a .htaccess file in public directory with:
RewriteEngine On
RewriteBase /testing/public/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Run $ composer install in you command line

Transferring codeigniter HMVC project from localhost to live server

I made a web application on codeigniter HMVC. I tested it on local server and the following link works perfectly fine by giving me a login form, the link : http://localhost/bird_vision/users/login, where my directory structure goes like this bird_vision/application/modules/users/users.php (users->module's name, users.php->controller's name). Now I posted the whole "bird_vision" folder to web using filezilla.
- changed the base_url in config.php file to domain_name
- Made some changes in .htaccess file
# Customized error messages.
ErrorDocument 404 /index.php
# Set the default handler.
DirectoryIndex index.php
# Various rewrite rules.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$10 [L,QSA]
</IfModule>
Now when I write bird_vision.se/bird_vision/users/login in my address bar it gives me 404 page not found. Although when I when type birdvision.se/bird_vision/welcome it gives me welcome to codeigniter page.
Please I need help as my all hardwork making this project is at stake. Thanks in advance.
I figured the problem was not with HMVC but was with codeigniter version 3.0. When it comes to unix(which was the operating system running on my server), it is case sensitive. So when I tried to access the controller it could'nt find the file because of case sensitivity and a 404 popped out everytime.
My folder structure before was something like :
-application
-->modules
--->users
---->controllers
----->users.php
And the link on which I was getting 404 was www.example.com/users/login
where "users" in the link is controller's name within the "controllers" folder under "modules" folder in my case named as users.php and "login" is the function inside the controller.
All I had to do was to change the case of the first letter of my module and controller name. Now my directory looks like
-application
-->modules
--->Users
---->controllers
----->Users.php
note : capitalized "U" in Users module and Users controller.
And the the url I used to access the users controller was : www.example.com/Users/login
And I was back in business.

Moving codeigniter project from localhost to cpanel

I am trying to run my codeigniter website on the server.But I don't have a clue that what settings should I perform.
I find the following link to move the files and do the specified settings but still its not showing me the home page of my website.
Here's what I've done till now.
I moved the codeigniter website's application and system folder on the root directory while my .htaccess file along with my assets and index.php is inside public_html.
Here's my directory structure.
-/home/mysite
-public_html
-index.php <-- the path for system is set to '/home/mysite/system' and for application folder is '/home/mysite/application'
-.htaccess
-system
-application
I've performed the following settings as mentioned in the link.
$config['index_page'] = "";
$config['base_url'] = "http://myurl.com/";
$config['server_root'] = $_SERVER['DOCUMENT_ROOT'];
$config['uri_protocol'] = 'AUTO';
$route['default_controller'] = "home_controller";
Here's my .htaccess file.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Now I don't know why my home page is still not appearing when I enter the url to my site.
upload your application folder, system folder, assets folder, index.php, .HTACCESS inside your public_html folder
You need to do few steps:
update 'application/config/config.php' for base_url
update 'htaccess' file for RewriteBase (if needed)
update file permission (if needed)
update 'aplication/config/database.php' for database settings
if still you face issue, then you need to debug like:
print something in index controller and walk through along the function sequence called and then views.

issue with shifting Kohana 2.4 from root location to make it accessible via a directory?

I have developed a kohana project 2.4 version, with i has been developed by configuring virtual host and we are accessing it using some domain aa.com, now i have to move the project to folder named kohana and make it access via aa.com/kohana. If i access it this way then my url changes, So the css & js file are not included since the src url i have provided like /public/css/ so it's not working, same goes for calling a controller. like il be calling a controller using this format /user/login/. now the url when i click to shows like aa.com/user/login which is not found, in turn it should automatically comes like aa.com/kohana/user/login. Is there any way by changing the htaccess file or hacking routes.php file. ?
I should able to automatically append /kohana/ before the url.
Please suggest me a method how it can be achieved.
Yes there is!
I've only started after kohana 3.0 but you can just change the rewritebase.
In your .htacces it probably says "rewritebase /"
Change this to your new directory. "rewritebase /kohana/"
If 2.4 has a bootstrap (i'm not sure) somewhere it should say "base_url". You change this the same as the .htaccess. /kohana/.
edit: here's an example:
# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /kohana/
# Protect application and system files from being viewed
RewriteRule ^(application|modules|system) - [F,L]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT,L]

How to use mod_rewrite in Apache2?

I´m trying to do a simple redirection with Apache2 with mod_rewrite. I've installed the module in my Apache and I´ve set a webpage in localhost/file1/file2/page.html. I´m writing this in my 000-default file:
RewriteEngine On
RewriteRule elegantdirectory/page.html file1/file2/page.html [L,NC]
So now if I try to access to localhost/elegantdirectory/page.html, the server is supposed to show me the page.html I have in file1/file2. Any ideas why isn't it working?
Try including bounds and a leading slash in your RewriteRule:
RewriteRule ^/elegantdirectory/page.html$ /file1/file2/page.html [L,NC]

Resources