removing index.php on codeigniter are found easy using .htaccess,
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
but when needed to be on other ports? it doesn't work, why? and how to make it work?
in http://localhost:85/foldersite seems working, but when calling a controller it's not found, such as http://localhost:85/foldersite/mycontroller
yet the same .htaccess when deployed in server hosting these are just fine calling the controller because it didn't use any different port than 80 ..
and in file config.php and route.php already set as follows
$config['base_url'] = 'http://localhost:85/foldersite';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
$route['default_controller'] = 'welcome';
$route['404_override'] = '';
I think I just have the same issue as yours, and I managed to solve it just about couple of minutes ago.
Please consider to read this documentation page: CodeIgniter URLs. Under the section of "Removing the index.php file" you'll be informed about Apache mod_rewrite enabled.
Then, I implemented a tutorial from Digital Ocean and it worked well. Just try it.
In addition, I have .htaccess content that exactly the same with yours. Except, I didn't modify any value from $config['base_url'] and $config['index_page'].
I hope it helps.
Related
In my site, the base ur is
base_url = 'localhost/cl/'
I want to redirect to 'localhost/cl/index.php/welcome' when they enter 'localhost/cl/'. I used .htaccess file to redirect but it isn't work. How could I do this? this is what i used in .htaccess
Redirect 301 / http://localhost/cl/index.php/welcome
update
i couldn't find any solution to fix this using htaccess. I put a if statement in my default controller that redirect me to desire page.
if(current_url() == base_url()) {
redirect(base_url().'index.php/welcome/');
}
Thanks everyone for give me your valuable time.
routes.php can handle it.
LINK
https://www.codeigniter.com/userguide3/general/routing.html
Follow these step to solve your issue.
Add this code in .htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|bootstrap|dist|plugins|css|js|images|robots\.txt)
RewriteRule ^(.*)$ index.php?$1 [L]
In config.php
$config['base_url'] = 'http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].'/ci/';
$config['index_page'] = '';
in routes.php
$route['default_controller'] = 'welcome';// Your controller name as landing page.
If it not working means, you need to enable mod_rewrite in Apache
All the best.
I use CodeIgniter 3.1 in my project. Everything is running well in localhost, but when I upload to server, all controllers that using redirect didnt work. It only shows blank page. Here my htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
</IfModule>
Please, help me find this solution. Does CI version is the main problem? or the htaccess itself? This is my first time upload my project to server and I hope I didnt miss something important .. thanks
[EDITED]
I use another server, it works fine. Maybe the problem is in the server.
[EDITED]
Horray... Problem solved. Just put ob_start() at the begining every .php.
(more information , visit http://kakaeriel.com/mengatasi-cannot-modify-header-information/)
Thanks for everyone who helped me find this solution.
I assume your host could have same config as Godaddy's. You could try this https://github.com/bcit-ci/CodeIgniter/wiki/Godaddy-Installation-Tips
In /application/config/config.php set $config['base_url'] like this
$config['base_url'] = 'http://[hostname]/'; //like www.google.com
Here is my htaccess file and it works somewhat. Not matter what controller I specify it always goes to the home page
<IfModule mod_rewrite.c>
RewriteEngine On
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#This last condition enables access to the images and css folders, and the robots.txt file
RewriteCond $1 !^(index\.php|css|js)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
This is my website URL
http://automationmetrics.local/automation/
Thoughts?
Some things I usually check when this happens to me:
Have I enabled the mod_rewrite module in Apache?
Have I set $config['index_page'] to blank?
If the above works, here's the one that I use, that's working on my end:
https://gist.github.com/petrepatrasc/6925413
If you're STILL out of luck, then try fiddling with the $config['uri_protocol'] parameter - I remember that I could only get it to work on Windows (with IIS at the time) using REQUEST_URI as a value. Might be related to that.
The first two rules get triggered on all the files, just like it says in the comment. So this one:
RewriteCond $1 !^(index\.php|css|js)
seems redundant and removing it should solve the issue you're having.
i have installed codeigniter and i want to remove the index.php from url when i access localhost/aplication/index.php. i have set uncomment mod_rewrite.so from httpd.conf en this is my .htaccess file :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
its succes when i acces url from localhost/aplication/index.php/data/users/12 but not with this url localhost/aplication/data/users/12.
how can i fix this??
Try to follow this page about codeignitor pretty urls. Your rules look correct, but I'm terrible with regex.
Some things to look into would be checking if mod_rewrite is available by using phpinfo();. Also step three in that link talks about enabling mod_rewrite using a2enmod. And make sure you restart Apache.
check your config file there should be a line that says:
$config['index_page'] = 'index.php';
You can either set this variable to just '' or you can comment this line out completely, either way it is part of the process of removing the index.php from your codeigniter urls.
this is how you remove the index.php:
htaccess file in the root folder:
RewriteBase /
RewriteEngine on
RewriteCond $1 !^(index\.php|images|js|css|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
for managing some static pages like: example.com/about , example.com/contact, example.com/terms etc
got to config routes file and edit:
//the controller that will be when it is exampl.com
$route['default_controller'] = 'YOUR_MAIN_CONTROLLER_NAME_HERE';
//I creted this for pages that are created dynamically or for displaying error when I want
$route['404_override'] = 'friendlyPages';
Right now i'm working on a webshop project in codeigniter.
In the end there will be multiple webshops on subdomains, and a frontpage on the main domain.
It's supposed to be all dynamic so that the webshops get their own subdomains.
The shop information is in the database. Lets say I have a mysql table which contains info like this:
webshop: Bobs shop
webshop_subdomain: bobsshop
And so on.
Now in a .htaccess file I want to make a rewrite rule so that bobsshop.mydomain.com will be rewritten to mydomain.com/bobsshop/ since i'm working in Codeigniter with controllers.
You should bear in mind that the index.php also has to be rewritten out and there should also be the possibility to make subpages like bobsshop.mydomain.com/contact/
I will make a php script which will check if the subdomain exists in the database and if it doesn't exist then the visitor will see a 404.
My DNS setup looks like this ATM:
mydomain.com xxx.xxx.xxx.xxx
*.mydomain.com xxx.xxx.xxx.xxx
Where xxx.xxx.xxx.xxx is my server IP.
I've really never worked with htaccess / mod_rewrite before.
Can it be done? And are there anyone who can help me make this?
Sorry for my English. I hope you understand what I'm trying to do.
Thanks in advance
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} ^((?!www\.)(?!mydomain\.com)[^\.]+)\.
RewriteRule ^(.*)$ http://www.mydomain.com/index.php?/%1/$1 [L]
Input URL - http://adasd.mydomain.com/test
1 RewriteCond %{HTTP_HOST} ^((?!www\.)(?!mydomain\.com)[^\.]+)\.
This condition was met
2 RewriteRule ^(.*)$ http://www.mydomain.com/index.php?/%1/$1 [L]
This rule was met, the new url is http://www.mydomain.com/index.php?/adasd/test
The tests are stopped, using a different host will cause a redirect
Output URL - http://www.mydomain.com/index.php?/adasd/test
You can then remove the index.php from the URL by
Open config.php from system/application/config directory and replace
$config['index_page'] = "index.php" with $config['index_page'] = ""
Implementing the above .htaccess file
In some case the default setting for uri_protocol does not work properly. To solve this problem just replace $config['uri_protocol'] = "AUTO" with $config['uri_protocol'] = "REQUEST_URI" in system/application/config/config.php