Home > Backend Development > PHP Tutorial > How Can I Remove 'index.php' from My CodeIgniter URLs?

How Can I Remove 'index.php' from My CodeIgniter URLs?

DDD
Release: 2024-12-21 11:06:10
Original
958 people have browsed it

How Can I Remove

Removing "index.php" from CodeIgniter URLs

In CodeIgniter, the default URL format includes "index.php" in the path, which can be unsightly and inconvenient. To remove this redundancy, follow these steps:

Step 1: Create .htaccess File

Place a file named ".htaccess" in the root folder of your web application.

Step 2: Add Rewrite Rules

Add the following Rewrite rules to your .htaccess file:

RewriteEngine on
RewriteCond  !^(index\.php|[Javascript / CSS / Image root Folder name(s)]|robots\.txt)
RewriteRule ^(.*)$ /index.php/ [L]
Copy after login

Explanation:

  • RewriteEngine on: Enables the Rewrite Engine in Apache.
  • RewriteCond: Matches URLs that do not start with "index.php" or specific folders like JavaScript, CSS, images, or robots.txt.
  • RewriteRule: Rewrites all matching URLs to redirect them to "/index.php/$1". This sends all requests to the index.php front controller, regardless of whether "index.php" appears in the URL.

Alternative Version:

For a more customizable version, you can refer to this snippet:

http://snipplr.com/view/5966/codeigniter-htaccess/
Copy after login

The above is the detailed content of How Can I Remove 'index.php' from My CodeIgniter URLs?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template