CodeIgniter - Cannot access to Controller file - codeigniter

I tried to use the .htaccess file to make the index.php disappear from the URL.
Here is my current .htaccess file :
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|image|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L,QSA]
</IfModule>
I used the site_url() function to load my page like this :
<li><div>Home - Corporate</div>
And I am having this issue :
The requested URL /mysite/welcome/corporate was not found on this
server.
In the Welcome.php file, I have a function called corporate :
public function corporate() {
$this->load->view('index-corporate.php');
}
I changed the config file already like this :
$config['index_page'] = '';
I feel like my problem is basic but can't find a way to solve it !
Thanks for your help

Thanks, my problem was coming from my controller name : I forgot the capital letter at the begining (welcome instead of Welcome)

Related

Masking URL in HTML

I have one HTML page. Assume the URL is
http://localhost/local/local.html
but i want to mask the URL as
http://localhost/local/abc
can we do like this?
Create a .htaccess file in your root of your domain and add the following in that file:
RewriteEngine On
RewriteRule ^local.html$ http://localhost/local/abc/ [R=301,L]
In .htaccess add lines:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php?query=$1 [QSA,L]
When you visit https://localhost/local/abc in index.php parse $_GET["query"] how you want.
You can achieve the required action using a htaccess rule ,
Learn about htaccess at :
What is .htaccess file?
.htaccess rule you can implement is follows :
Options +FollowSymlinks
RewriteEngine on
rewriterule ^local/local.html (.*)$ http://localhost/local/abc$1 [r=301,nc]

how to configure codeigniter hmvc in subdomain

H,
I'm using codeigniter hmvc framework.i don't know how to configure this fo subdomain. i've installed it but not working. any help please.
project/
application/
controller/installer
modules/
default controller is pointed to installer.php
$route[default_controller] = 'installer';
but unable access the controller.
No matter it is hosted in subdomain or main domain. You need to do couple of things to make it workable.
Step one
Config base_url in config.php as follows:
$config['base_url'] = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "https" : "http");
$config['base_url'] .= "://".$_SERVER['HTTP_HOST'];
$config['base_url'] .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
Step two Check your .htaccess. It should looks like as bellows:
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Note: .htaccess vary depending on server. In some server (e.g.: Godaddy) need to use the following .htaccess:
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
Hope it will help you.
find this file
application/config/config.php
edit here thats all
$config['base_url'] = "http://subdomain.example.com/";

CodeIgniter Rewrite URL: remove index.php from url

My apps url is
http://localhost/myapp/admin/index.php/projects
and I want to rewrite it as
http://localhost/myapp/admin/projects
I followed user guide
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
for this but not work for me.
Please follow these steps:
1- If you work on localhost please enable mode_rewrite in php.ini
2- Create a .htaccess file under project folder and paste this (please change 'project' to your project folder name):
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /project/index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /project/index.php
</IfModule>
3- Edit this line at application/config.php:
$config['index_page'] = "";
Thank /* ActuallyMAB */: Your code actually works. The above code works on localhost (WAMP Server on windows).
If you have placed your codeigniter project in some folder such as your directory structure looks like:
C:\wamp\www\proposal
So, You have to replace
RewriteRule ^(.*)$ /project/index.php/$1 [L]
to
RewriteRule ^(.*)$ /proposal{or your folder name}/index.php/$1 [L]
if this is not the case with your project {you have put your codeigniter directly into www folder}, then remove the folder name from the above code as it looks like;
RewriteRule ^(.*)$ /index.php/$1 [L]
also do not forget to change
$config['index_page'] = 'index.php';
to
$config['index_page'] = '';
in your config folder {config.php}
I hope others have also provided the same answer, but since the above code works in my project and i felt to provide some details too.

CodeIgniter routing always through index.php?

CodeIgniter beginner here. The base URL of my website is 'http://localhost/routing/'.
// config.php
$config['base_url'] = 'http://localhost/routing/';
I'm simply trying to route the url 'http://localhost/routing/admin' to the admin controller using the following rules but it doesn't work. Instead I have to use 'http://localhost/routing/index.php/admin'.
$route['default_controller'] = 'seasons';
$route['admin'] = 'admin';
$route['404_override'] = '';
Question: is there a way to remove 'index.php' from the url?
Make changes in .htaccess file and config.php
application/config.php
$config['index_page'] = '';
.htaccess
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
is there a way to remove 'index.php' from the url?
Yes, as well as being a very popular question on SO, it is covered in the CodeIgniter documentation (which is very good and I highly recommend reading).
In your .htaccess write this. Also look for additional information : Codeigniter Guide
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt) # exceptions
RewriteRule ^(.*)$ /index.php/$1 [L]

404 is given when trying to access existing controller in CodeIgniter

I am working on a fairly new install of CodeIgniter 2.0.
I have a htaccess-file containg this code
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
Going to the URL http://www.estiem.no/ESTIEM/CI/ works,
but http://www.estiem.no/ESTIEM/CI/site/index does not. It gives a 404. The controller Site exists, and contains the method 'index'
Any ideas what might be wrong?
You need to remove / from index.php
RewriteRule ^(.*)$ index.php/$1 [L]
It is a htaccess problem, back when everyone passed that code around we found that a lot of hosts didn't like it and you could hack it with a ? or this or that until it ended up looking like a jigsaw puzzle (the condition that is) but using a brilliant htaccess (not sure who the first was but like 500 have taken credit) you will never have to change it again (well not never but it will work 99% of the time un edited):
# 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/$1 [L,QSA]
</IfModule>
Trust me I have had the same issues and spend hours on google when i should have come here or even the CI wiki (since that is the first place I seen it), you would not believe how many issues are solved in CI with just that bit of htaccess. they really should add it to the repo.
I just noticed that since you have your CI install in a subfolder, you need to account for that in the .htaccess rewrite:
/ESTIEM/CI/
So your .htaccess will look like:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /ESTIEM/CI/index.php/$1 [L]
That should fix it (sorry late edit, due to #BrianOrtiz 's comment)
Try to access the controller with: localhost/site/index.php/controller
If that does not work maybe because the CI is case sensitive
localhost/site/controller == c:...\site\controller.php
localhost/SITE/controller == c:...\SITE\controller.php
else
<?php
controller Mycontroller extends Controller {
}
?>
will be named mycontroller.php in the controllers folder
If all else fails replace your htaccess by this:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]

Resources