WordPress Tutorial: Removing ‘index.php’ in URLs
I have personally noticed that at first, I could not change my WordPress permalinks without including index.php in the URL. I could change the permalink structure through my settings but I kept getting a 404 when I viewed the pages afterwards. To solve this problem, read on!
Original URLs:
http://heartdrops.org/index.php/visitor/wp-removing-index-php-in-permalinks/
http://heartdrops.org/index.php/my-first-blog/
URL after this tutorial:
http://heartdrops.org/visitor/wp-removing-index-php-in-permalinks/
http://heartdrops.org/my-first-blog/
It might just be something little, but I found that it really made a difference and made the URLs shorter.
You will need the following:
- to have your site running on WordPress, obviously
- an FTP program
- a file editor (such as Notepad)
- an internet browser, obviously
You will need to create a file called .htaccess. Note that you might already have one in your site files. Please check this first.
Log in to your site using your FTP program and search for .htaccess in the main directory. If you have one, download it.
If you don’t have one, create one by opening Notepad, and saving the file under the name .htaccess simply by typing it in the “file name” box.
With your .htaccess file, whether it is newly created or already has information, paste the following code into the file. If you have information in the file, simply place it on a new line at the bottom.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Now save the file, and upload it to your main directory (should be public_html or what you first see when you log in to FTP).
The next step is to log in to WordPress on your website.
Go to Settings > Permalinks. Select the Custom Structure radio button. The input box is where you put the structure of links. Mine is set to /%postname%/.
Other variables can be used, like /%year%/, /%monthnum%/ and /%day%/. More can be found on Using Permalinks at The Codex.
Click “Save Changes” and when you view your pages, they should load without the index.php appearing in the URL. You won’t need to set up redirects or anything in this case as they will automatically redirect.