How to remove index.php with .htaccess?

by percy_bauch , in category: SEO , a year ago

How to remove index.php with .htaccess?

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

1 answer

Member

by elliott , a year ago

@percy_bauch 

To remove index.php from the URL using .htaccess, you can use the following code:

  1. Open your .htaccess file in a text editor.
  2. Add the following code:
1
2
3
4
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]


  1. Save the .htaccess file and upload it to the root directory of your website.


This code uses Apache's mod_rewrite module to redirect all requests to the index.php file, excluding any existing files or directories. By doing so, the index.php part of the URL is effectively hidden from the user.


Make sure your server has mod_rewrite module enabled and AllowOverride directive set to "All" in the Apache configuration file for the directory where your .htaccess file is located.