How do i get rid of index php?

To remove the “index.php” from your site’s URLs, you will first need to make sure your server is set up to pass would-be 404 requests off to Craft’s index.php file behind the scenes.

If you’re running Apache, you can do that by creating a redirect in your site’s .htaccess file. If you don’t already have one, create a new file called “.htaccess” in your site’s web root.

Save this inside your .htaccess file:


  RewriteEngine On

  # Send would-be 404 requests to Craft
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
  RewriteRule (.+) index.php?p=$1 [QSA,L]

That rewrite rule basically says, “if a request is coming in that doesn’t map to an existing folder or file, pass it along to index.php instead.”

With that file in place, try accessing a page on your site (besides your homepage), without the “index.php”. If it works, great! If not, you should check with your host to see why the .htaccess file isn’t working.

That’s great, but my URLs are still outputting with “index.php” #

The last step is to tell Craft that your site is set up to handle URLs without “index.php” in them. (Craft does its best to determine that for itself, but it only checks every 24 hours, and sometimes it gets it wrong.)

You can tell Craft not to include the “index.php” by opening up craft/config/general.php, and adding this to the array:

    'omitScriptNameInUrls' => true,

With that in place, Craft will take your word for it and stop performing its daily checks.

But seriously, my URLs still have “index.php” in them #

If you’re on Apache, your httpd.conf file probably has AllowOverride None set for your site, effectively disabling all .htaccess file changes. Change it to AllowOverride All, restart Apache and you should finally be set. Also make sure mod_rewrite is enabled.

The original answer is actually correct, but lacks explanation. I would like to add some explanations and modifications.

I suggest reading this short introduction https://httpd.apache.org/docs/2.4/rewrite/intro.html (15mins) and reference these 2 pages while reading.

https://httpd.apache.org/docs/2.4/mod/mod_rewrite.html https://httpd.apache.org/docs/2.4/rewrite/flags.html


This is the basic rule to hide index.php from the URL. Put this in your root .htaccess file.

mod_rewrite must be enabled with PHP and this will work for the PHP version higher than 5.2.6.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /index.php/$1 [L]

Think %{REQUEST_FILENAME} as the the path after host.

E.g. https://www.example.com/index.html, %{REQUEST_FILENAME} is /index.html

So the last 3 lines means, if it's not a regular file !-f and not a directory !-d, then do the RewriteRule.

As for RewriteRule formats:

How do i get rid of index php?

So RewriteRule (.*) /index.php/$1 [L] means, if the 2 RewriteCond are satisfied, it (.*) would match everything after the hostname. . matches any single character , .* matches any characters and (.*) makes this a variables can be references with $1, then replace with /index.php/$1. The final effect is to add a preceding index.php to the whole URL path.

E.g. for https://www.example.com/hello, it would produce, https://www.example.com/index.php/hello internally.

Another key problem is that this indeed solve the question. Internally, (I guess) it always need https://www.example.com/index.php/hello, but with rewriting, you could visit the site without index.php, apache adds that for you internally.


Btw, making an extra .htaccess file is not very recommended by the Apache doc.

Rewriting is typically configured in the main server configuration setting (outside any section) or inside containers. This is the easiest way to do rewriting and is recommended

By default, PHP platforms such as WordPress and Codeigniter append index.php at the end of website URL, which is not really required. Here are the steps to remove index.php from URL using .htaccess in Apache web server. You can use these steps to remove index.php from WordPress, Codeigniter and other PHP websites.

We will basically redirect the index.php to URL without it. For that we will need mod_rewrite Apache module.

Before proceeding further, please ensure that you have enabled mod_rewrite in Apache web server. Here are the steps to enable mod_rewrite in Apache. At the end of it, you will have created a .htaccess file for your website.

1. Open .htaccess file

Open terminal and run the following commands to open .htaccess file. We have used the default file path of .htaccess file. You can change it as per your requirement.

$ sudo vi /var/www/html/.htaccess

2. Remove index.php from URL

Add the following lines in .htaccess file.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

Let us look at each line above. The first line enables mod_rewrite if it is not enabled already.

The second line matches URLs that are not files. The third line matches URLs that are not directories. So we are looking to match URLs that are neither files nor directories.

The last line means that if the two RewriteCond statements before it are matched for a URL, then it will be redirected to URL without index.php in it.

3. Restart Apache web server

Restart Apache server to apply changes

$ sudo systemctl restart httpd

Now if you open browser and visit http://your_domain_or_IP/index.php you will be redirected to http://your_domain_or_IP. Replace your_domain_or_IP with your domain or IP address. Similarly, if you visit URL like http://your_domain_or_IP/index.php/folder1/folder2 you will be redirected to http://your_domain_or_IP/folder1/folder2

  • About Author

How do i get rid of index php?

Can I delete index php?

To remove the “index. php” from your site's URLs, you will first need to make sure your server is set up to pass would-be 404 requests off to Craft's index. php file behind the scenes. If you're running Apache, you can do that by creating a redirect in your site's .

How do I remove a site index?

php from WordPress, Codeigniter and other PHP websites..
How to Remove index. php from URL. We will basically redirect the index. ... .
Open . htaccess file. ... .
Remove index. php from URL. ... .
Restart Apache web server. Restart Apache server to apply changes $ sudo systemctl restart httpd..

Why is index php in my WordPress URL?

php appears in the URL might be because the structure of permalinks is not set properly in WordPress Settings. So to verify if the structure of permalinks is set properly, let's check the permalink tab in WordPress Dashboard.

How do I remove a php from a URL?

How to Remove ..
Open htaccess file. Open terminal and run the following command to open . htaccess file. ... .
Remove . php extension from URL. ... .
Restart Apache web server. Restart Apache server with following command $ sudo systemctl restart httpd..