Search code examples
wordpressapache.htaccessmod-rewritepermalinks

Remove index.php from Wordpress URLs


I am new to Wordpress but tried all documentation and Stack Overflow posts for possible solutions but none of them have worked so far.

I have verified that mod rewrite is enabled and working as expected. Followed all steps mentioned here. https://wordpress.stackexchange.com/questions/105795/remove-index-php-from-permalinks

Also restarted Apache couple of times but still getting 404 errors when I remove index.php path from Permalink Settings.

Renamed the wordpress directory to blog to access the site at www.xyz.com/blog. Now the requirement is to access any blog posts with www.xyz.com/blog/2018/02/09/my-wp-post without index.php in the URLs.

We don't have any other CMS content other than WP for the blog site.

Permalink settings(Custom Structure): /index.php/%year%/%monthnum%/%day%/%postname%/

.htaccess file contents:

BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /blog/ RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /blog/index.php [L] </IfModule>


Solution

  • I spent ton of time trying many different approaches answered here or elsewhere but none of them fixed my issue.

    This is what I did and it has fixed my issue.

    1. Change permalink settings to remove index.php
    2. Update/Save .htaccess content that's at the root of the WP installation if it's not allowed to be updated automatically when we change permalink settings in WP admin panel.
    3. This is the important step since not many Q & A mentioned this in detail, other than wordpress documentation here. Specifically check AllowOverride settings and change it to All, Apache httpd.conf will not load the .htaccess contents without this change. Of course mod_rewrite must be enabled in the server if it's not already done. In our case it's enabled by default, so didn't have to mess with this step.
    4. Also make sure FollowSymLinks option enabled as mentioned in the WP documentation.
    5. Last but not least, make sure you restart the Apache service/server for the changes to take effect.

    Entry in httpd.conf file:

    <Directory "/var/www/html/blog">
    Options FollowSymLinks
    AllowOverride All