WordPress multisite .htaccess causes 500 error on old *.php URLs

admin2025-06-05  3

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!

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!

Share Improve this question edited Dec 27, 2018 at 13:55 benedict_w asked Dec 27, 2018 at 12:49 benedict_wbenedict_w 5912 gold badges7 silver badges17 bronze badges 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
Add a comment  | 

1 Answer 1

Reset to default 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.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749064490a316048.html

最新回复(0)