Redirect all URLs to homepage except core WordPress files

I’ve recently gained access to a domain which used to have a very large site and product base, however the old host turned it off and all the URLs are lost. I am using WordPress on the domain (previously it used an e-com shop called Kyrptronic) and have set up a simple landing page. So far there are over 20,000 not found URLs and I need them to redirect to the homepage (except for css and jpg files that I am using on the landing page).

I tried to redirect all old links straight to homepage however this means the core wordpress files become inaccessable and when you try and click anything in the backend E.g. Plugins – it redirects to the homepage. Here is the code I used in the htaccess file.

Read More
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} !.(gif|jpe?g|png|css|js|xml)$
RewriteRule (.*) / [R=301,L]
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

Is there a htaccess code snippet that can redirect all URLs other than jpgs, pngs and NOT the entire wordpress and website directory with .php file extensions?

The site has too many not found URLs to do one by one.

Hope this makes sense, it’s my first post on here!!

Thanks

Related posts

Leave a Reply

1 comment

  1. You could try something like this (it must e above the wordpress routing rules):

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !.(gif|jpe?g|png|css|js|xml|php)$
    RewriteRule ^ / [R=301,L]