Wordpress xmlrpc.php 301 Moved Permanently - wordpress

I have a site setup on Digital Ocean using their Wordpress droplet installer. I have then installed Jetpack.
The Site Health tool reported that Jetpack is not connected and that I should visit the Jetpack.com debugger. I did so and put my website in. The error I get:
XML-RPC is not responding correctly ( 200 )
When visiting the url mywebaddress.com/xmlrpc.php I just get redirected to the main URL of the site.
As recommended by Jetpack I went to a terminal and ran
curl -A 'Jetpack by WordPress.com' -d '<methodCall><methodName>demo.sayHello</methodName></methodCall>' https://mywebaddress.com/xmlrpc.php
When I do so I get the following coming back.
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved here.</p>
<hr>
<address>Apache/2.4.29 (Ubuntu) Server at mywebaddress.com Port 443</address>
</body></html>
I have checked the .htaccess file and this contains only comments.
I have checked /etc/apache2/apache2.conf and can find no redirects there.
So my question is, can anyone tell me what might be causing this 301 Redirect?

Found the answer
I have just located this file:
/etc/apache2/conf-enabled/block-xmlrpc.conf
This had this inside
<IfModule mod_rewrite.c>
<Directory / >
Redirect 301 /xmlrpc.php /
</Directory>
</IfModule>
This file was causing the redirect. Have commented out its contents for now.
I didn't create this, so I must assume DigitalOcean create it when doing the Wordpress one click install

I found this file under /etc/apache2/conf-available/ rather than /conf-enabled/

Related

How do I make the landing page of website appear on Google and not "Index of /"?

I have recently made my WordPress website live and want it to be visible on Google Search. However, when specifically searching for the website, Google does not show the site title or description entered in WordPress, but rather "Index of /" and a bit of server info as the page summary. Does anyone recognize this, and have some ideas on how to fix this?
Apache2 is running on an Ubuntu 18.04 server and everything is updated. I have both an index.html file and obviously an index.php file in the DocumentRoot directory specified in the Virtual Host file for apache. And have specified to use index.php first in the .htaccess file. I've also tried to add the URL of the page to Google Search Console and added a sitemap, but with no effect.
You can add these lines to .htaccess files (its located in root of the website). What it does its redirects any trafic you got on http://example.com to https://example.com Please check both locations in separate browsers (and again with removed cache) on how it works. SOmetimes apache can be configured so it wouldn't work out of the box (like it can require additional fixes to redirection code or to the additional blocks etc...)
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]

How to redirect a specific url with subfolder to another url in Windows nginx server?

I am using Windows nginx server and I have the following code in my nginx.conf file:
location /store {
rewrite ^(.*)$ /?page=myshop redirect;
}
However, upon accessing my domain shop.domain.com/store then it displays an error message saying 404 Not Found instead of redirecting to shop.domain.com/?page=myshop
Something is broken.
I've been searching for a solution but without success. I need to redirect upon trying to access shop.domain.com/store/ to shop.domain.com/?page=myshop
Maybe I should enable rewrite module somewhere in nginx or what may cause this behavior?
Thank you in advance!
With .htaccess
Redirect /store /?page=myshop
Alternative: store.php with content:
<meta http-equiv="refresh" content="0; url=shop.domain.com/?page=myshop" />

Wordpress REST API (wp-api) 404 Error: Cannot access the WordPress REST API

I have been using the Wordpress REST plugin WP-API for months now while developing locally with XAMPP. I recently migrated my site to an EC2 instance and everything is working fine except I now get a 404 with the following message whenever I try to access any endpoint on the API:
The requested URL /wordpress/wp-json/ was not found on this server
Pretty permalinks are enabled with the following structure http://.../wordpress/sample-post/ which works fine when navigating to a specific post in the browser.
Here are some details about my setup:
Wordpress 4.4.1
Not a Multisite
WP REST API plugin 2.0-beta9
Apache 2.2.22
Ubuntu 12.04.5
Any help would be greatly appreciated as I have gone through SO and the WP Support forums for several hours and am out of ideas. Thank you!
UPDATED NEW WAY
I also faced similar problem in a local project. I used index.php after my project url and it worked.
http://localhost/myproject/index.php/wp-json/wp/v2/posts
If it displays a 404 error then update permalinks first (see "Paged Navigation Doesn't Work" section
If it works, maybe you need to enable mod_rewrite, on ubuntu:
a2enmod rewrite
sudo service apache2 restart
Installation
The REST API is included in WordPress 4.7! Plugins are no longer required, just install the latest version of WordPress and you're ready to go.
If you're before 4.7:
Download plugin from here: http://v2.wp-api.org/
install and activate it.
Usage
To get all posts:
www.mysite.com/wp-json/wp/v2/posts
For the search functionality, searching for test post looks like this:
/wp-json/wp/v2/posts?filter[s]=test
I had this problem with the latest WordPress 4.7+. In my case the REST API only worked after I changed the permalinks setting to something other than "Plain", which was the default setting for my installation.
On WPEngine and WP 4.9.2 I only had to update permalinks to get fresh, newly installed site to return v2 API calls. What I did:
Create site
Browse to http://yoursitename.wpengine.com/wp-json/wp/v2/posts
get 404
Go to admin, settings, permalinks, choose "Post Name"
Click "Save Changes"
Browse to http://yoursitename.wpengine.com/wp-json/wp/v2/posts
success. page displays JSON response
It turned out to be a problem with the Apache configuration.
First, I deleted the .htaccess file in the root wordpress directory.
Next, I navigated to /etc/apache2/sites-enabled and opened 000-default
All of the AllowOverride variables were set to None, which I replaced with All.
That did the trick!
It is the file permission error, apply the following solution:
Edit this file /etc/apache2/apache2.conf
Change /var/www/ Permissions from "None" to "All"
Restart the apache2 server.
First you've to Check if the WordPress REST API is enabled or not
The best way to check is to visit this URL: https://yoursite.com/wp-json.
If you see some JSON response, REST API is enabled.
If it’s showing some error page or returns to home page, REST API is not enabled. Then we've to enable it first.
In this case, you've to Enable Permalinks
Visit your page's admin page (Visit https://yoursite.com/wp-json)
settings > Permalinks (visit https://yoursite.com/wp-admin/options-permalink.php)
Make sure Plain is not selected
Choose Post Name (it's a best one)
Then click on Save Changes. That will rewrite/repair your .htaccess
Please see the helping screenshots below:
Source
I solved this issue through following steps:
Navigate to ..\Apache24\conf\httpd.conf and search for LoadModule rewrite_module modules/mod_rewrite.so.
Enable rewrite module by removing the # mark.
Replace all the cases of AllowOverride None to AllowOverride All.
Don't forget to restart apache server. :)
Adding "AllowOverride All" (as hinted by other authors before) to my apache virtual host configuration on my Ubuntu server via SSH did the trick for me:
sudo vi /etc/apache2/sites-available/my-website-name.com.conf
and also (if you use letsencrypt):
sudo vi /etc/apache2/sites-available/my-website-name.com-le-ssl.conf
The files should then look like:
<VirtualHost *:80>
# or <VirtualHost *:443> for the SSL configuration
# [...]
DocumentRoot /var/www/my-website-name.com/public_html
<Directory "/var/www/my-website-name.com/public_html">
# this allows .htaccess files (e.g. generated by Wordpress)
# to overwrite the apache configuration on a directory basis:
AllowOverride All
</Directory>
# [...]
</VirtualHost>
Don't forget to disable and re-enable the site and reload apache to apply the new configuration:
sudo a2dissite my-website-name.com.conf
sudo a2dissite my-website-name.com-le-ssl.conf
sudo a2ensite my-website-name.com.conf
sudo a2ensite my-website-name.com-le-ssl.conf
sudo service apache2 reload
I had to manually make a .htaccess, set it to chmod 664, and copy the permalink rules into it.
I also played around with
Settings > Permalinks
Manually updating .htaccess via the code at the bottom of the permalinks page after clicked "Save"
Adding "index.php" as one of the other answers suggests
Making sure mod rewrite was enabled via a2enmod
I found that mysite/wp-json/ was not working, but mysite/?rest_route=/ was normal. This was breaking some, but not all, the REST API features used on my site.
The answer to this turned out to be a recent change to how I was running my server. This had broken REST API but this was not apparent until later.
I had changed this domain from using Apache to using nginx, and I had not correctly transferred the .htaccess customisations. The quick solution to this problem was therefore to change back to using Apache. This restored the site to working order immediately.
I will be changing this domain back to nginx in the future but when I do, I will test it and be careful not to affect the REST API.
I had moved the WordPress install from a subdirectory to another, so in my case the problem was due to the WordPress config in the .htaccess files. It was trying to redirect every page but the homepage to the old directory. It was just a matter of updating olddir to newdir...
This tripped me up more than once so I thought I'd put it here...
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /olddir/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /olddir/index.php [L]
</IfModule>
# END WordPress
I faced the same problem when I migrated my site from cPanel to Google Cloud Compute Engine Instance; problem was of file permissions which was initially caused due to difference in PHP versions of current deployment from previous deployment.
Here is the fix How to deal with GCP WordPress error "This page isn’t working example.com is currently unable to handle this request. HTTP ERROR 500
If you website is https://example.wordpress.com (on wordpress) for example, use the below link which will give you the JSON response irrespective of any API settings/Permalinks etc..
https://public-api.wordpress.com/rest/v1.1/sites/example.wordpress.com/posts
If you want to see all the available endpoints use this -
https://developer.wordpress.com/docs/api/console/
Remember to replace **$site** with your domain
Find the latest documentation here -
https://developer.wordpress.com/docs/api/
If you are on Windows OS change the Permalink Settings as follows:
Custom structure: /index.php/%postname%/
I was facing same issue on localhost and I solved this issue with just set RewriteBase Path in .htaccess file which is available at root folder of WordPress project setup.
**Example:**
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /[folder-name]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /[folder-name]/index.php [L]
</IfModule>
If you have tried the other solutions on this page and they haven't worked, I had success with checking for additional .htaccess files in the root folder above your public_html folder (or wherever you have installed WordPress).
I found an extra one which may have come from a previous installation or been accidentally moved there - it was giving conflicting instructions to the 'real' .htaccess file. Deleting it fixed the problem for me.
For me on new website I didn't had Nginx pretty links setting enabled I add this tolocation / block
try_files $uri $uri/ /index.php?$args;
Try to remove any
order deny,allow
deny from all
allow from ...
from you .htaccess.
I read through a whole bunch of articles and eventually discovered there was a force site to be https plugin installed and activated on my local, however there is no certificate set up. It was making the requests for https when I should have had the https plugin deactivated.
Once deactivated, I was able to make connections to REST API.
Not a very in depth answer but it is was my answer. Hope this saves someone some time!
On WordPress 6
You can use this URL and no need for URL Rewrite and no need to change your Permalink settings (I saw Gutenberg editor is using this URL to access REST)
http://example.com/index.php?rest_route=/wp/v2/posts

How to change OpenShift Jenkins to use HTTP instead of HTTPs

I create an application Jenkins on Openshift, but when I tried to visit http://[app_name]-[domain_name].rhcloud.com/, it will be redirected to https://[app_name]-[domain_name].rhcloud.com/.
I curl the http address, the result is :
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>302 Found</title>
</head><body>
<h1>Found</h1>
<p>The document has moved here.</p>
<hr>
<address>Apache/2.2.15 (Red Hat) Server at [app_name]-[domain_name].rhcloud.com Port 80</address>
</body></html>
If I do not want to be redirected to https, what should I do?
I searched in my openshift folders, but cannot find any helpful things
You should change it on your .htaccess file.
RewriteRule ^https://[app_name]-[domain_name].rhcloud.com/(.*) http://[app_name]-[domain_name].rhcloud.com/$1 [R=301,NC]

How to rewrite .aspx to .html or .php with htaccess

I'm trying to rewrite some URLs that have a .aspx extension to .html. I looked around and saw that you can put something like
RewriteEngine On
RewriteCond %{QUERY_STRING} ^file=(.+)$
RewriteRule ^(.+)\.aspx$ $1.php?f=%1
in the htaccess to rewrite any .aspx to .php. However, when I put that in the .htaccess file, it doesn't seem to work for me. mod_rewrite is enabled and the site is on a Linux server so those are not the issue. If I try to go anywhere with a .aspx extension, I get a "Server Error in '/' Application." error.
You can see this by going here http://www.netstar.co.uk.php5-20.websitetestlink.com/about-us.aspx. Any help for this would be greatly appreciated...it has been a thorn in my side for quite some time.
You say that the site is on a linux server and mod_rewrite is enabled.
However, when I navigate to the link you provided, I get the following HTTP response headers:
Cache-Control private
Content-Type text/html; charset=utf-8
Server Microsoft-IIS/7.0
X-AspNet-Version 2.0.50727
X-Powered-By ASP.NET
Date Thu, 31 Mar 2011 15:24:33 GMT
Content-Length 1508
Which tells me that no, it's not a Linux server, no it isn't running Apache, and no it doesn't have mod_rewrite enabled.
But I'm not surprised by any of this, because you're writing aspx code, which would normally not be run on a linux/apache server anyway.
I suggest you investigate the IIS equivalent of mod_rewrite. Try starting at this question here on SO: mod_rewrite equivalent for IIS 7.0
My usual mistake: you need to enable .htaccess files in httpd.conf (or, on e.g. Ubuntu, in your site configuration file). In the main <Directory> block (or is it <Location>?) there's probably a directive that ignores .htaccess files in the root directory, or in all directories.
It's probably easiest to just add your rewrite rules to the root <Directory> instead. Remember to restart apache after changing these files.

Resources