This post assumes you’re having a hard time removing the index.php file name from the URL slug of your WordPress site.
Looks like something like this:
domain.org/index.php/%postname%
This means one of two things:
- Your web server (Apache) doesn’t have the mod_rewrite module enabled
- Your mod_rewrite module is not recognizing your .htaccess file
First thing you want to do is make sure that you have made the appropriate setting update in your WordPress settings page. Looks like this:
Assuming you have this set, we now have to switch our focus to your server. In this instance, I assume you’re on a linux machine (Ubuntu 18.04) and working with Apache. If you’re not, it should give you general instructions that help you with your machine.
First verify that your server allows an .htaccess to be created at the root of your site. You should have something that looks like this:
# ls -la /var/www/domain.org/
total 204
drwxr-xr-x5 www-data www-data4096 Oct5 21:29 .
drwxr-xr-x5 root root4096 Oct5 04:43 ..
-rw-r–r–1 www-data www-data 235 Oct5 20:51 .htaccess
-rwxr-xr-x1 www-data www-data 418 Sep 252013 index.php
-rwxr-xr-x1 www-data www-data 19935 Jan62018 license.txt
-rwxr-xr-x1 www-data www-data7415 Mar 182018 readme.html
Open your .htaccess file, it should have something like the following:
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
If you have this, this is all good. You’re making progress. Now, we’ll switch our focus to the web server.
Again, assuming Ubuntu 18.04, you’re going to want to enable your rewrite module. You do that like this:
# a2enmod rewrite
Go ahead and restart your web server:
# systemctl restart apache2
Now you want to insert your directives into the virtual host file for the site you’re working on. So it’ll look something like this:
# vim /etc/apache2/sites-available/domain.conf
This is where I screwed up. I put the syntax inside the syntax, but it needs to be outside. It should look something like this:
<VirtualHost *:80>
ServerAdmin [your email]
ServerName domain.org
ServerAlias www.domain.org
DocumentRoot /var/www/domain.org/
ErrorLog ${APACHE_LOG_DIR}/domain.org.error.log
CustomLog ${APACHE_LOG_DIR}/domain.org.access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =domain.org [OR]
RewriteCond %{SERVER_NAME} =www.domain.org
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
<directory /var/www/domain.org>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</directory>
Go ahead and restart Apache again for good measure:
# systemctl restart apache2
This should do the trick. Navigate to your site, select the post and it should work.