1
votes

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>

4
your question is Too Broad . Edit your question with adding your permalink structure, what is look of your url now, what do you want to achieve, does your wordpress installation contain some other cms/frameworks/static html, does it located into subfolder, providing .htaccess file and etc.Samvel Aleqsanyan
Please see the edits and let me know if I should any other details.cnu

4 Answers

5
votes

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

2
votes

Assuming Ubuntu 16.04 & Apache2

1) Activate mod_rewrite. It's available but not enabled with a clean Apache 2 installation.

sudo a2enmod rewrite

2) Restart Apache

sudo systemctl restart apache2.service

3) Setup .htaccess

(Note: Apache reccomends using a server configuration file over inserting rules into .htaccess, however, for this example, inserting rules into .htaccess is sufficient because of the negligible performance hit.)

sudo nano /etc/apache2/sites-available/000-default.conf

Insert the following in 000-default.conf

<VirtualHost *:80>
    <Directory /var/www/html>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

4) Restart Apache

Repeat step 2

5) Create .htaccess in the web root.

touch /var/www/html/.htaccess

Insert the following into .htaccess

RewriteEngine On

6 Configure the URL Rewrite (Note: Assuming index.php)

sudo nano /var/www/html/.htaccess

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

mod_rewrite is a useful Apache module that can be used effectively to ensure human-readable URLs and good SEO results. If you'd like to learn more about mod_rewrite, take a look at Apache's mod_rewrite Introduction and Apache's official documentation for mod_rewrite.

0
votes

In a nutshell, as @Cnu as mentionned, the problem very few resources on the internet touch on is the fact that your apache configuration must contain an AllowOverride FileInfo directive for wordpress rewrites to work without /index.php/.

Since Apache 2.4, AllowOverride default setting is "None", which is often a roadblock in making "pretty urls" work (in this case ditching the index.php). As @cnu mentionned, you should read carefully this resource : https://wordpress.org/support/article/using-permalinks/.

  1. Make sure to have mod_rewrite enabled -> (to be sure create an info.php you will remove later containing the line <?php phpinfo();?>) at the root of your blog and call https://domainofyourb.log/info.php)
  2. Make sure your .htaccess is writable by wordpress. (permission and ownership should be allowing your webserver (often with the username "apache") to edit the file.
  3. Change your wordpress permalinks settings, and check that .htaccess file is correctly written.
  4. Check that your apache configuration (etc/httpd/conf/httpd.conf in some linux distros) contains the directive AllowOverride FileInfo within your blog's <Directory></Directory> section
  5. Options directive to FollowSymLinks should be the default, but if Options directive is mentionned, add FollowSymLinks for good measure.
  6. when all that is done, don't forget to restart your Apache server. (sudo service httpd restart in my case, ymmv).

P.S : wrote this answer because I can't comment (don't have rep) on cnu's answer, and wanted to correct 1. allowoverride doesn't need to be set to ALL, it can be set to simply "FileInfo", 2. update the link to wordpress doc, and 3. provide background on the change in apache 2.4 that causes this issue.

-1
votes

Go to admin page, Dashboard -> Settings -> Permalink Settings -> Custom Structure, select /%postname%/ or, /%year%/%monthnum%/%day%/%postname%/ up to you.