1

I have setup a new multisite WordPress install. Everything works fine, except Google is still crawling old URLs (which had a .php extension).

These URLs are now showing a 500 error, which seems to be due to an htaccess issue - i.e. these URLs are not hitting WordPress. (I am currently using the standard WordPress multisite htaccess code.)

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]

I need to add a rewrite to the site's .htaccess that will remove the .php extension for the files that have them, and that are not found on the server (i.e. exclude WordPress core files like wp-login.php, etc.)

I used this code to remove the .php extension

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ / [L,QSA]
</IfModule>

This resolved the 500 error and allowed me to setup redirects for the old site using the wp-redirect plugin as I had originally intended, but it causes some issues with styles and images loading on some of the sub-folder multisites, so I think it needs improving!

3
  • What is the format of the URLs you want to redirect from? Presumably these don't map to actual files? And to what URL format are you wanting to redirect to?
    – MrWhite
    Commented Dec 27, 2018 at 13:16
  • I just need to remove the .php extension for these files (that seems to resolve the 500 error), they don't map to actual files, but then I can setup redirects using wp-redirect plugin.
    – benedict_w
    Commented Dec 27, 2018 at 13:22
  • @MrWhite I've updated the question with more info, that should clarify things better - I hope!
    – benedict_w
    Commented Dec 27, 2018 at 13:35

1 Answer 1

0

Try something like the following at the top of your .htaccess file:

Options -MultiViews

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.+)\.php$ /$1 [R=302,L]

The above redirects any URL that ends in .php that does not map to a physical file and removes the .php extension in the redirection.

Although these requests (with a .php extension) shouldn't be triggering a 500 error in the first place? If the above redirect resolves this, then it would seem to imply that it is WordPress itself that is triggering the 500 error?


I used this code to remove the .php extension

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ / [L,QSA]
</IfModule>

This resolved the 500 error ...

This code is more likely to cause a 500 error than fix it? This doesn't "remove the .php extension" - it simply routes all URLs to the document root, which triggers mod_dir to route the request to index.php.

7
  • I tried your code, an it causes a "too many redirects" error, accessing /index
    – benedict_w
    Commented Dec 27, 2018 at 13:42
  • What is the loop you are seeing?
    – MrWhite
    Commented Dec 27, 2018 at 13:45
  • How can I find out? I just get ERR_TOO_MANY_REDIRECTS in Chrome
    – benedict_w
    Commented Dec 27, 2018 at 13:46
  • They are all just going to /index which has a 302 status
    – benedict_w
    Commented Dec 27, 2018 at 13:53
  • 1
    Thanks - this answers the question, and seems to have resolved the issue on the site. I am going to look further into what is going on as I realised the old URLS were in a sub-folder so might be conflicting there with multisite.
    – benedict_w
    Commented Dec 27, 2018 at 17:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.