404 on Wordpress post permalinks - wordpress

I'm getting a 404 when I click permalinks to my posts. I updated the .htaccess file per the documentation instructions but I still get them. That .htaccess code is in my /blog/ directory.
In my wp-admin control panel, I have it configured to do "post name" permalinks. The post permalinks work fine when I use the default, but they are 404'ing when I use the "post name" permalink setting.
Background: I'm on Apache/2.2.20 (Ubuntu) Server.

Just updating the .htaccess file would not do the trick. You need to find out if your mod_rewite.c module is enabled. If not, you need to enable it by going to console and typing in this:
sudo a2enmod rewrite
and afterwards restart your apache server.
service apache2 restart
If even that doesnt work, probably your userdir module is not enabled. For this reason you need to enable it
sudo a2enmod userdir
and then try enabling the rewrite module if still not enabled.
You can read up on this further here.

Is your mod_rewrite on?
Otherwise you'll need full URL like http://example.com/index.php/yyyy/mm/dd/post-name/

If only the "post name" setting doesn't work, it might be due to a conflict, maybe you have a post with a name that's also present on another post, page or category.

I Got Answer. It's easy only.
1) Go to WAMP logo in right-bottom of Task-bar of Windows.
2) Click left button
3) then Apache -> Apache Modules
4) Tic(select) the rewrite_module
5) that's all.

Related

Publishing or uploading failed. Error message: "The response is not a valid JSON response"

Today I got an issue in WordPress. When I try to create a new page and uploading a new image in the WordPress admin section, I try to find out the solution, but I didn't get it... So after sanding an hour I got a solution...
Error
"Publishing failed. Error message: The response is not a valid JSON response."
Go to settings>permalinks. Select "Post name" and save.
Try updating your posts/pages. If it doesnot work, try selecting another option in the settings>permalinks.
Right now, you can use the Classic Editor plugin for fixing this issue.
The answer for the error is the editor I didn't know, but there is a new editor issue. If you are getting the same issue, then please use the below plugin. For fixing these issues, I'm doing R&D on this issue. If I get an exit solution, then will I make an update soon...
I had the same problem on a local dev environment and found the issue was due to rewrite permissions. Make sure your .htaccess file has the proper permission.
sudo chmod 755 .htaccess
After permissions are set, save your permalink settings. If the problem still exists, make sure mod_rewrite is enabled. The following will work for apache2 on Ubuntu.
sudo a2enmod rewrite
sudo systemctl apache2 restart
If still not working, your apache config is probably too strict. The following should do the trick for apache2 on Ubuntu. Edit /etc/apache2/apache2.conf and look for the root directory block. It's normally the one with /var/www like below. You will probably see AllowOverride None. Just change it to All like below for your local, but you probably want to do some research and be more secure on a production server.
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
After the change is made do another restart on apache and all should be good.
sudo systemctl apache2 restart
Changing the permalink settings as mentioned previously fixed the problem for me. If you keep "Post name" as the permalink setting, then the .htaccess file needs to be writable by wordpress.
Alternatively the below can be pasted at the bottom of .htaccess file. Mod_rewrite changes are executed from the bottom of the file first.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Maybe you have a security issue with mixed content (HTTP and https URLs).
Step-1
1. 1. Check your Wordpress URL. Go to Settings -> permalink then click plain and save a page. then remove error
Step-2
Check your Wordpress URL. Go to Settings -> General
Change Wordpress Adress and Site Adress to https://
This solved the problem for me
Navigate to Settings > Permalinks. Select the permalink structure to Post name and save. Now try saving your post/page.
Here I have shared the screen-shot for your reference.
The problem should have been resolved.
Once your issue is resolved then you can select an old option in Permalinks if you want.
Note: If you have already selected Post Name then you need to select other option for reset permalink.
Go to /etc/nginx/sites-available/
open default file --> sudo vi default or sudo nano default
Add Below line to the location:
Add the comment :
#try_files $uri $uri/ =404;
Add this line : try_files $uri $uri/ /index.php?$args;
See the screenshot below described with red line :
I just installed classic editor plugin and it sorted out the “The response is not a valid JSON response” problem.
I had the same "not a valid JSON response" error when trying to publish my content. WordPress seems to do a JSON post when publishing a new post/page so I checked the network tab in my Developer Tools. If you check the "response" tab for this JSON call you might see some more details about this invalid JSON response.
In my case (yours might be different) some deprecated debug message was outputted before the actual JSON data and messed up the response. After fixing the deprecated message publishing worked again.
<br />
<b>Deprecated</b>: Automatically populating $HTTP_RAW_POST_DATA is deprecated and will be removed in a future version. To avoid this warning set 'always_populate_raw_post_data' to '-1' in php.ini and use the php://input stream instead. in <b>Unknown</b> on line <b>0</b><br />
<br />
<b>Warning</b>: Cannot modify header information - headers already sent in <b>Unknown</b> on line <b>0</b><br />
{__NORMAL_JSON_DATA_HERE__}
Now, here there are two server blocks, first one is running on port 80.
for second server block there is a port 443 where you should implement the below code.
server{
#ssl configuration
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
# try_files $uri $uri/ =404; // comment this block
try_files $uri $uri/ /index.php$is_args$args;
}
}
Now exit and restart nginx server.
~$ sudo service nginx restart
you are done. enjoy.
In My case, it was a Firewall issue. A ModSecurity firewall rule was triggered for the website. I contacted the hosting provider (NameCheap), they identified the issue and then whitelisted the triggered rule on the server. Then the problem was resolved.
Looks like this still has not been fixed.
A workaround that worked for me (posting in case it works for someone else too) - in my case I was using an HTML block which was causing the issue. What I did was to add a Paragraph block > Edit as HTML. It resolved the issue for now. It's a shame that WP didn't look into it yet, seems like it's been happening for a while.
I had this same error and the cause in my case was a shortcode used in the page and the function that defined the shortcode was using 'echo' to output the data rather than using 'return'
I'd been getting the same error message when adding and/or updating pages, in addition to various other random errors. I was getting the errors on both my local development server and my webhost. When changing to one of the default themes (e.g. twenty nineteen), the errors would go away. For me, the problem turned out to be in my page template files. I'd noticed that when choosing a template for a newly created page, I'd have multiple choices with the same name.
I have several page template files (e.g. about-page.php, contact-page.php, services-page.php, etc.). When creating these files, since most of these pages were similar, I would just copy/paste from an existing file to make a new xxxx-page.php file. However, in some of those copied files (not all), I'd forgotten to modify the 'Template Name' (at the top of the file).
After I'd gone through and made sure all of my template files had unique names, the JSON error went away. All of my other errors disappeared as well. I'm using Wordpress 5.4.
My issue was .htaccess related. I got the hint from LucasBr's comment about a ".htaccess configuration problem". Since I had copied the site to my local dev environment. I needed to update the custom mod_rewrite settings to match my setup.
The important lines were:
RewriteBase /
and
RewriteRule . /index.php [L]
They had previously been set to access a sub-directory site.
I have some echo in some of my custom plugins, so this was also causing this issue.
I had the persisting issues. Before I could find the solution, I replaced PHP 8, as this was custom PHP Installation.
But nothing worked.
The solution was found during Drupal Installation.
Enable Opcache(only for Drupal though)
Allow Mod rewrite, Allow all(in my httpd.ini file there were three occurrences of Mod Rewrite,
And they were changed to None to All again none all this was small letter, and final one None to All
Restart httpd with httpd -k restart (CMD as Administrator)
This resolved.
I encountered the same kind of problem for a different reason with one of my client and never saw it as a potential solution.
If you enabled a W.A.F (like cloudflare or similar), one of the side effects can be this error, so be sure to disable to disable you waf if none of the other solutions are working.
If you use mod security 3 with Wordpress, you might get this message:
Publishing failed. The response is not a valid JSON response.
To remove it, you would need to add this rule to your exclusions file called
REQUEST-900-EXCLUSION-RULES-BEFORE-CRS
as follows:
# Remove Publishing failed. The response is not a valid JSON response.
SecRule REQUEST_HEADERS:Host "example.com" \
"id:1025,\
phase:2,\
pass,\
nolog,\
chain"
SecRule REQUEST_URI "#beginsWith /wp-json/wp/v2" \
" ctl:ruleRemoveById=933210,ctl:ruleRemoveById=949110"
You might need to change the rule id and change example.com to your domain name. After that, do this:
sudo nginx -t
if no problems were detected, restart nginx:
sudo service nginx restart
sudo systemctl restart nginx
This is a permalinks error.
Do these steps to fix it (depending upon the cause in your scenario) as explained here: https://wordpress786.com/updating-failed-error-message-the-response-is-not-a-valid-json-response/ :
go to settings > permalinks and save them once again
if you're on nginx, go to site nginx conf file and make sure that it contains the rules for wordpress permalinks (usual nginx configurationn for wordpress, ask me if confused)
restart nginx if you make any edits to conf file
If you face issue on image upload follow this: https://navinrao.com/the-response-is-not-a-valid-json-response/
I was getting this issue while updating normal text too.
The issue I face was due to having javascript:void(0) keyword inside my link () .
Please be sure if your content has keyword containing javascript
before updating.
<i class="fa fa-linkedin" aria-hidden="true"></i>
After I remove javascript:void(0) ; it works fine.
Have a nice time :)
Try removing any redirects to the WordPress site including subdomains.

Silverstripe install root folder public

I have installed silverstripe 4 into the /var/www/html folder in apache.
However, when I go to the url, I have to use "localhost/public/index.php" in order to obtain the main page. I thought I was to be able to just go to "localhost" to find the defaut page. What am I to do if I want to have a main page without people having to specify "/public/" before it?
Thanks.
Normally, your localhost website can be resolved without adding /public/ if the following 2 things are configured correctly.
Enable Apache mod_rewrite
Having .htaccess rewrite config in /var/www/html
Troubleshooting
Check if you got the right .htaccess in /var/www/html. Basically, this Apache config file will forward all the requests to /public/ folder.
If .htaccess is fine, make sure your mod_rewrite is enabled in your Apache. Check this link.

loading Module mod_rewrite on httpd.conf file causes "Forbidden" error on localhost

Im on a mac running Sierra 10.12.2 and apache 2.4.23
I set up a localhost environment and a virtualhost for the domain cumsa.mx and installed wordpress on it. Without getting too into detail now, some changes were made on Git that modified the wp permalinks, and hence the .htaccess file through wp.
I went to my main httpd.conf file and told it to load the module mod_rewrite as suggested by a colleague since that was necessary to be able to modify the htaccess file. Regardless of that, activating this module results in my local environment for cumsa.mx to become "Forbidden".
Can anyone think of any idea why this wouldbe the case or which permissions I need to modify and how? Thanks!

Wordpress Permalink (Postname)

I have problem with my Wordpress permalink. I'm currently running Ubuntu 14.04 LAMP server installed and my Wordpress root is located on /var/www/html2/ . I tried to change permalink to postname "/%postname%/". When I test one of my page its says that 404 Not Found.
I've looking around about my problem and tried many tutorials but no luck. In my opinion, my Wordpress access seems not working but I'm not sure because I'm newbie for this. Please anyone can help me solve this problem.
Thanks In Advance
Manually create a ".htaccess" file and save it in your main WordPress directory. (This is the one with the wp-admin, wp-includes, and wp-content folders.)
Go to the Ubuntu terminal and type:
sudo chown -v :www-data "/enterYourFilePathHere/.htaccess"
You should see a line printed saying that the (group) file ownership has been changed to www-data (Apache2).
Give Apache2 write access to the file:
sudo chmod -v 664 "/enterYourFilePathHere/.htaccess"
You should see a line printed saying that the mode of the file has been retained.
Next, we have to allow WordPress to write to the .htaccess file by enabling mod_write in the Apache2 server. Type the following in the terminal:
sudo a2enmod rewrite
You should see a line printed saying that it is enabling mod rewrite and reminding you to restart the web server
So let's do that. Restart the web server, Apache2, for the changes to take effect by typing:
sudo /etc/init.d/apache2 restart
We are all done with the command line prompt; you can close the command line window now.
Go into your WordPress admin panel (i.e. http://yourDomain/wp-admin). Go to the Settings --> Permalinks and select the permalink format of your choice. Hit the "Save Changes" button.
DONE! Go to your site and check any page (other than your homepage) to ascertain that everything is working as expected.

Wordpress Permlinks 404 Not Found

I have installed the latest WordPress on my EC2 Ubuntu 13.1 server.
Once I have changed the permlinks to use /%post-name%/, I encounter 404 not found for posts.
I have followed almost everything here, but still having the issue.
http://www.felfelworld.com/2013/02/12/page-not-found-permalink-wordpress/
FYI, I remember I did disable the directory listing for my apache server using SELinux (if I remember it correctly)
in order to have the Permalinks working you need:
Apache web server with the mod_rewrite module installed
The FollowSymLinks option enabled
FileInfo directives allowed
An .htaccess file
You can read more on the codex page.

Resources