✓ Solved

.htaccess - wordpress & 404 pages not working

My wordpress websites run on apache on ubuntu. My 404 pages are not working properly.

The only time I can type in a junk email address and wordpress finds it, is when I do it like this:
http://mysite.com/index.php/my-junk-url

But if I type it in like this:
http://mysite.com/my-junk-url

Then wordpress does not catch it. It just shows in my browser that no such url exists.

However, in the root of my wordpress folder is a .htaccess file and it contains this code, which I believe is supposed to redirect everything but it doesn't.

Here's what my .htaccess file looks like:
<ifmodule mod_rewrite.c=""> RewriteEngine On RewriteBase / RewriteRule ^index.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </ifmodule>

Can anyone tell me what is going wrong?

10 Replies

✓ Best Answer

@Rhodesia writes:

It is as if none of the changes I'm making to the .htaccess file at the root of my wordpress website are having any effect on apache2 at all.

I wrote earlier:

Does your "main" configuration file allow these directives to be in a .htaccess file? Does your main configuration file or one of its <Include>s contain something like
 

<Directory /path/to/directory>
   AllowOverride All
</Directory>

 
where your .htaccess file has the filesystem path /path/to/directory/.htaccess?

This doesn't happen by magic. See: https://fullstackwebstudio.com/locations/coding-blog/apache-and-overriding-with-htaccess/

Is mod_rewrite loaded/configured? sudo a2enmod rewrite (then restart apache2(8)).

You should also fix the syntax error that sudo apache2ctl configtest found…

-- sw

You write:

<ifmodule mod_rewrite.c=""> 
   RewriteEngine On 
   RewriteBase / 
   RewriteRule ^index.php$ - [L] 
   RewriteCond %{REQUEST_FILENAME} !-f 
   RewriteCond %{REQUEST_FILENAME} !-d 
   RewriteRule . /index.php [L] 
</ifmodule>

I surrounded your apache2(8) config snippet by ``` (three backquotes) to make it more readable. You should do that in the future. While <IfModule></IfModule> are case-insensitive, from a readability/diagnostic perspective, it would be better if you wrote them like the apache2(8) documentation presents them. That being said…

  • I have never, in all my considerable number of years in dealing with apache2(8), seen the ="" notation in an <IfModule> directive. I couldn't find it documented either.

  • Does your "main" configuration file allow these directives to be in a .htaccess file? Does your main configuration file or one of its <Include>s contain something like

<Directory /path/to/directory>
   AllowOverride All
</Directory>

where your .htaccess file has the filesystem path /path/to/directory/.htaccess?

  • Do you get the same results if your <IfModule></IfModule> snippet is part of the main configuration rather than in a .htaccess file?

  • Can your configuration pass a syntax check?

sudo apache2ctl configtest

-- sw

I have placed 3 back quotes before the lines and it seems to be better. I had tried uploading a direct screenshot here but I see that can't be done. This system is very sensitive because even pasting my ctrl-c from nano or from type .htaccess still gave weird results.
I hope this is more understandable.

My current .htaccess file below is the normal, standard default one that wordpress generates for each of it's systems. I don't understand what it's doing and why it can't catch out 404 errors. All this stuff is new to me. I'll go and try to enable the logs for mod_rewrite now and I'll get back to you.

# BEGIN WordPress # The directives (lines) between BEGIN WordPress and END WordPress are
# dynamically generated, and should only be modified via WordPress filters. # Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule>

Trust me, I used the preview view for the above before posting it and I see now it came out like junk still. Let me try again. What a nuisance this is. Are there any other characters I should know about that I can use?

Let's try this again:

# BEGIN WordPress # The directives (lines) between BEGIN WordPress and END WordPress are
# dynamically generated, and should only be modified via WordPress filters. # Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c> RewriteEngine On
RewriteBase / RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

I wish I could post an image here. I've done straight screen shots. It would be so simple.

I have tried to enable logging. I added these 2 lines:
RewriteLog "/var/log/apache2/zz-jl.log" RewriteLogLevel 9

Then I restarted apache2 but I don't see that new log appearing.
I can see the data coming into the access log.
But to me it's as if it is not doing anything new.

It's as if the logging isn't turned on.

RewriteLog "/var/log/apache2/zz-jl.log"
RewriteLogLevel 9

It is as if none of the changes I'm making to the .htaccess file at the root of my wordpress website are having any effect on apache2 at all.

I've checked and the owner of the file is www-data.

I have tried to do a syntax check as you suggested:
sudo apache2ctl configtest
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 66.175.214.247. Set the 'ServerName' directive globally to suppress this message
Syntax OK

Thank you very much for these answers. I'll look into it tomorrow. I really appreciate you efforts, otherwise I'd be lost. Thank you for your patience.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct