Home > Backend Development > PHP Tutorial > How to Remove 'index.php' from URLs in CodeIgniter?

How to Remove 'index.php' from URLs in CodeIgniter?

DDD
Release: 2024-11-11 22:14:03
Original
483 people have browsed it

How to Remove 'index.php' from URLs in CodeIgniter?

CodeIgniter URL Rewriting Issues: Removing 'index.php' from URLs

CodeIgniter, like most PHP frameworks, allows you to remove 'index.php' from your website's URLs for a cleaner and more user-friendly appearance. This can be achieved through URL rewriting.

To remove 'index.php' from your URLs in CodeIgniter, follow these steps:

  1. Modify Application Configuration:

    • In the application/config.php file, make the following changes:

      $config['base_url'] = 'http://'.$_SERVER['SERVER_NAME'].'/Your Ci folder_name';
      $config['index_page'] = '';
      $config['uri_protocol'] = 'AUTO';
      Copy after login
  2. Create .htaccess File:

    • Create a .htaccess file in the root directory of your application (where your index.php file is located). Paste the following code into the file:

      RewriteEngine on
      RewriteCond  !^(index\.php|resources|robots\.txt)
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.*)$ index.php/ [L,QSA]
      Copy after login
  3. Enable URL Rewriting:

    • a. Ensure that the mod_rewrite module is enabled in your Apache server configuration.
    • b. Restart your Apache server.

Make sure to replace Your Ci folder_name in the base_url configuration with the actual name of your CodeIgniter installation directory.

Accessing Specific Pages:

After implementing URL rewriting, you should be able to access your pages without the 'index.php' suffix. For example, you can access your 'about' page by visiting localhost/ci/about. Note that you do not need to create an 'about' directory within the 'application' directory.

If you encounter any issues, such as a 500 Internal Server Error, double-check your configuration and ensure that the mod_rewrite module is enabled correctly.

The above is the detailed content of How to Remove 'index.php' from URLs in CodeIgniter?. 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