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!
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
.