Wordpress HTTP Request 501 Internal Server Error - wordpress

Hello i have digitalocean one click application contains Wordpress.
I add domain to my server and create SSL certificate for my server.
https://example.com works good but when i request
http://example.com its redirect -> http://myserverip.com and gives that error:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator at webmaster#localhost to inform them of the time this error occurred, and the actions you performed just before this error.
More information about this error may be available in the server error log.
Additionally, a 301 Moved Permanently error was encountered while trying to use an ErrorDocument to handle the request.
Please help me about it. I try to redirect http to https but its not work!
Here it is my .htaccess file contains:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
# BEGIN WordPress
<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

Try this, worked for me:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTPS} =off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [QSA,L,R=301]
</IfModule>

Related

Woocommerce rest api not working 401 unauthorised

I have wordpress 5.4.1 and woocommerce 4.2 and ssl certificate from let's encrypt
I managed to get a response from the API before using query string https://www.store.com/wp-json/wc/v3/products?consumer_key=ck_XXXX&consumer_secret=cs_XXX but suddenly it stopped working giving me 401 unauthorized error. I am 100% sure about the keys.
I am using php with FastCgi and I read that sometimes the server dosn't read the authorization correctly so I tried the following
I added
<IfModule mod_setenvif>
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
</IfModule>
and
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
to my .htaccess file
Also I added
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
to my httpd.conf file after RewriteEngine on
I also installed the basic auth plugin https://github.com/WP-API/Basic-Auth
All of the above solutions failed to get a response from postman or insomnia with the same error 401 unauthorized.
I finally got the answer after 2 days
The best solution is to remove all the above and just add
RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization}]
so my whole htaccess block will look like:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization}]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Loading some pages causes AH00124 redirect error

I started getting Error 500 when loading some pages on my Wordpress site and found out it's because of AH00124 redirect error.
[error] - www.johndoe.com - AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace., referer https://www.johndoe.com/
This literally came out from nowhere since I didn't make significant changes to the site and the issue persists even after rolling back any possible changes.
Here is my .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?johndoe.com$
RewriteCond %{REQUEST_URI} !^/sito/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /sito/$1
RewriteCond %{HTTP_HOST} ^(www.)?johndoe.com$
RewriteRule ^(/)?$ sito/index.php [L]
</IfModule>
# BEGIN WordPress
<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
Here some pages that cause the error:
/blog
/wp-admin/edit.php (on post)
2019/03/26/any-article/
I think I can't log into the Apache server because we only pay for a web hosting, so I guess I can't have a look at backtraces.

.htaccess redirect to subfolder with language tag

I have a website where the .htaccess redirects to a subfolder.
This is the content of the .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !^/v2/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /v2/$1
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ v2/index.php [L]
</IfModule>
# BEGIN WordPress
<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
Now when I install polylang and add a second language, it creates the URL example.com/en.
This URL gets me an error:
Internal Server Error The server encountered an internal error or
misconfiguration and was unable to complete your request.
Please contact the server administrator at webmaster#reeko.com to
inform them of the time this error occurred, and the actions you
performed just before this error.
More information about this error may be available in the server error
log.
When I open example.com/v2/en it does work properly. Now do I have to create a second redirection in my .htaccess?
Try this , put it before RewriteCond %{REQUEST_URI} !^/v2/ :
RewriteRule ^en/(.*)$ /v2/en/$1 [L]
Clear browser cache then test it .

Wordpress redirection loop error

I created a website few days back with a url http://abctest.com in wordpress. Now the website has been published to a domain http://www.bcdefg.com.
The server is same, I have not migrated the site, only the domain has been pointed to the same server. I have changed the wphome and wpsite url to respective domain.
What I want to achieve is to redirect all http://abctest.com or http://www.abctest.com requests to http://www.bcdefg.com.
I tried to use .htaccess redirection but that leads to Too many redirection error. Any solution ?
Below is my htaccess code.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !bcdefg.com$ [NC]
RewriteRule ^(.*)$ http://www.bcdefg.com/$1 [L,R=301]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Error is on your rewriteCond : your host is www.bcdef.com and not bcdef.com (www is important)
try replacing this
RewriteCond %{HTTP_HOST} !bcdefg.com$ [NC]
by this :
RewriteCond %{HTTP_HOST} !www.bcdefg.com$ [NC]

How to move WordPress form HTTP to HTTPS

I have following code in my .htaccess file of a wp site
# BEGIN WordPress
<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
I have done all the thing need for a WordPress site to operate in HTTPS now my site is opening in both the format i.e in HTTP and HTTPS, but if the user type example.com it goes to http not in https so to solve this I add few more code to solve this issue
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yoursite.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.yoursite.com [NC]
RewriteRule ^(.*)$ https://www.yoursite.com/$1 [L,R=301,NC]
# BEGIN WordPress
<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
but after adding this my site in not opening it says "ERR_TOO_MANY_REDIRECTS"
How to solve this issue, I want the user to go directly to https
The problem is that you're not checking if https is being used, so it just constantly tells the browser to go to https://www.yoursite.com/$1.
You can use %{HTTPS} to check whether the request uses https.
RewriteEngine on
RewriteCond %{HTTPS} !^on$ [NC]
RewriteRule ^(.*)$ https://www.yoursite.com/$1 [L,R=301,NC]

Resources