Wordpress .htaccess disables my server 404 response

I have Wordpress and I am reasonably familiar with it as a basic user. I have recently upgraded my hosting package to include SSL. I mention that because it did cause some teething problems with Wordpress.

Wordpress is installed in a folder, so my main website is https://www.www.mywebsite.com and my Worpress is accessed at https://www.mywebsite.com/wpfolder/ this all works fine

I have 404 redirects on my main site to a custom page, and Wordpress takes care of any Wordpress 404 redirects to its own custom page.

After a previous discussion on Sitepoint I also added some 301 redirects so my canonical url is https://www.mywebsite.com and all domains now point there (I only have one physical domain and no duplicate pages - this is simply to stop Google seeing fake duplicate content)

Now my problem - the following .htaccess seems to work perfectly with everything :-

# 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>

# END WordPress

RewriteEngine On
RewriteCond %{HTTP_HOST} ^mywebsite.com [NC]
RewriteRule ^(.*)$ http://www.mywebsite.com/$1 [L,R=301]

If I remove the comment tags for the wordpress lines then my 404 redirect stops working for my main site

But am I messing up Wordpress by commenting out the Wordpress entries, is Wordpress as their comments state going to overwrite my .htaccess or does it have its own virtual one. I need to have the 301 redirects, I need the custom 404 redirects for both my site and the Wordpress site and I need to be sure Wordpress will work OK - is what I am doing OK, is there a better way, am I building problems for myself - thanks

You don’t seem to have anything in your .htaccess file to handle 404s.

Cheers
The custom 404 redirect for the main site is set up in the hosting control panel and works ok with a designated custom-page.html Wordpress seems to be taking care of Wordpress pages not found.

At levels above the Wordpress installation folder the server takes care of page not found and presents my custom page. At and below the Wordpress installation folder Wordpress detects page not found and presents the Wordpress page not found. That is working ok.

My problem is if I uncomment the Wordpress config lines in .htaccess it breaks, I really want to know if I am causing problems further down the line by commenting out this Wordpress code or if I should look at the whole redirect thing from a different angle. If commenting out the code is ok then I am happy - I have a working system .

I suspect you may need to switch off the handling of 404s in the control panel and add the following at the beginning of your .htaccess file

ErrorDocument 404 /custom-404.html
1 Like

OK, I can try that - is ‘at the beginning’ important ?

Probably not. :slight_smile:

No, you can place it anywhere really

2 Likes

All seems resolved - thanks guys

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.