How to change the codeigniter url using .htaccess file?

Member

by kadin , in category: Third Party Scripts , a month ago

How to change the codeigniter url using .htaccess file?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by cortez.connelly , 24 days ago

@kadin 

To change the CodeIgniter URL using the .htaccess file, you can use the following set of rules:

  1. Create a new file called ".htaccess" in the root directory of your CodeIgniter project.
  2. Add the following code to the .htaccess file:
1
2
3
4
5
6
7
8
Options +FollowSymlinks
RewriteEngine on
RewriteBase /

# Redirect all requests to the index.php file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]


  1. Save the .htaccess file.
  2. Make sure that mod_rewrite is enabled on your server.
  3. Test the new URL structure by accessing your CodeIgniter site. The URLs should now appear cleaner and more user-friendly.


Note: Always make sure to backup your .htaccess file before making any changes. Additionally, ensure that you have configured your CodeIgniter application to work with the new URL structure (e.g., updating the base_url in the config.php file).