How to remove 'index.php' from url in CodeIgniter?

How to remove index.php from URL in CodeIgniter?

I removed index.php from my configuration file and I ran my rewrite_module in Apache (2.2.11) and . htaccess file:

 RewriteEngine on RewriteCond $1 !^(index\.php|images|captcha|css|js|robots\.txt) RewriteRule ^(.*)$ /index.php/$1 [L] 

Now, whenever I click on any link, it shows that the URL was not found. What is the problem?

+4
source share
7 answers

Try it on . htaccess file: comments should help you configure it for you ...

This works great for me on several CodeIgniter websites. Also, if mod_rewrite is not installed, it will send you to page 404 (or you can change it for your purpose).

 <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / #'system' can be replaced if you have renamed your system folder. RewriteCond %{REQUEST_URI} ^system.* RewriteRule ^(.*)$ index.php/$1 [L] #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|(.*)\.swf|images|robots\.txt|css|docs|cache) RewriteRule ^(.*)$ index.php/$1 [L] </IfModule> <IfModule !mod_rewrite.c> # If we don't have mod_rewrite installed, all 404's # can be sent to index.php, and everything works as normal. ErrorDocument 404 /application/errors/404.php </IfModule> 

Check the virtual hosts file and see if these elements are installed - this may result in your .htaccess file rewriting URLs correctly

 Options FollowSymLinks AllowOverride All Order deny,allow Deny from all 
+4
source

This 100% works, I tried. Add only to the .htaccess file:

 RewriteEngine On RewriteCond $1 !^(index\.php|(.*)\.swf|robots\.txt) RewriteRule ^(.*)$ index.php/$1 [L] 
+3
source

I also had a problem with the rewrite rule suggested in the CodeIgniter user guide. I solved this by removing the slash before index.php

 RewriteRule ^(.*)$ index.php/$1 [L] 
+2
source

First of all, make sure you define a default controller . Then, make sure you build the URLs in such a way that the controller is associated with them. For instance,

Homepage:

 example.com/home/ 

Or for the About Us page:

 example.com/about/ 

Also double check that you have included the mod-rewrite module.

0
source

I also had this problem, and I found that Shane's answer helped me. I have my site settings in WAMP .

 RewriteBase /mysite/ 

mysite is an alias specified in Apache. This worked on all my sites.

0
source

.htacess

 RewriteEngine on #Any HTTP request other than those for index.php, #assets folder, files folder and robots.txt #is treated as a request for your index.php file. RewriteCond $1 !^(index\.php|assets|files|robots\.txt) RewriteRule ^(.*)$ index.php/$1 [L] 

after that go to application/config/config.php and change these two variables with the values ​​given below.

 $config['base_url'] = ''; 

and

$config['index_page'] = '';

0
source

For all my Codeigniter projects, I use the .htaccess code below:

 RewriteEngine on RewriteCond $1 !^(index.php|resources|robots.txt) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L,QSA] 

Hope this helps.

0
source

Source: https://habr.com/ru/post/1300171/


All Articles