postname giving URL was not found - wordpress

I have an issue by getting permalink to work on debian8.
My .htaccess looks like this:
# 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
and permission 666.
But then I change my permalink to postname instead of plain and I get:
requested URL was not found on this server
on all of my URLs except the start page.

WordPress uses Apache's "mod_rewrite" to serve pages and posts using permalinks, and it sounds like that module is not enabled on your server. To enable it, type sudo a2enmod rewrite, and then restart Apache. After that, permalinks should work.
You can also set any file permissions that you changed back to what they were originally.
Edit:
In your Apache config, you might also need to change the AllowOverride setting. The default on Ubuntu does not allow all .htaccess directives to work, so it's likely the same on Debian. You can use AllowOverride All or choose specific options instead. FileInfo is the one you will need for mod_rewrite. Apache's docs (2.4) for AllowOverride are here: https://httpd.apache.org/docs/2.4/mod/core.html#allowoverride

I solved my problem by using the below command
sudo a2enmod rewrite

Related

Remove index.php from Wordpress URLs

I am new to Wordpress but tried all documentation and Stack Overflow posts for possible solutions but none of them have worked so far.
I have verified that mod rewrite is enabled and working as expected. Followed all steps mentioned here. https://wordpress.stackexchange.com/questions/105795/remove-index-php-from-permalinks
Also restarted Apache couple of times but still getting 404 errors when I remove index.php path from Permalink Settings.
Renamed the wordpress directory to blog to access the site at www.xyz.com/blog. Now the requirement is to access any blog posts with
www.xyz.com/blog/2018/02/09/my-wp-post without index.php in the URLs.
We don't have any other CMS content other than WP for the blog site.
Permalink settings(Custom Structure):
/index.php/%year%/%monthnum%/%day%/%postname%/
.htaccess file contents:
BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
I spent ton of time trying many different approaches answered here or elsewhere but none of them fixed my issue.
This is what I did and it has fixed my issue.
Change permalink settings to remove index.php
Update/Save .htaccess content that's at the root of the WP installation if it's not allowed to be updated automatically when we change permalink settings in WP admin panel.
This is the important step since not many Q & A mentioned this in detail, other than wordpress documentation here. Specifically check AllowOverride settings and change it to All, Apache httpd.conf will not load the .htaccess contents without this change. Of course mod_rewrite must be enabled in the server if it's not already done. In our case it's enabled by default, so didn't have to mess with this step.
Also make sure FollowSymLinks option enabled as mentioned in the WP documentation.
Last but not least, make sure you restart the Apache service/server for the changes to take effect.
Entry in httpd.conf file:
<Directory "/var/www/html/blog">
Options FollowSymLinks
AllowOverride All
Assuming Ubuntu 16.04 & Apache2
1) Activate mod_rewrite. It's available but not enabled with a clean Apache 2 installation.
sudo a2enmod rewrite
2) Restart Apache
sudo systemctl restart apache2.service
3) Setup .htaccess
(Note: Apache reccomends using a server configuration file over inserting rules into .htaccess, however, for this example, inserting rules into .htaccess is sufficient because of the negligible performance hit.)
sudo nano /etc/apache2/sites-available/000-default.conf
Insert the following in 000-default.conf
<VirtualHost *:80>
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
4) Restart Apache
Repeat step 2
5) Create .htaccess in the web root.
touch /var/www/html/.htaccess
Insert the following into .htaccess
RewriteEngine On
6 Configure the URL Rewrite (Note: Assuming index.php)
sudo nano /var/www/html/.htaccess
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
mod_rewrite is a useful Apache module that can be used effectively to ensure human-readable URLs and good SEO results. If you'd like to learn more about mod_rewrite, take a look at Apache's mod_rewrite Introduction and Apache's official documentation for mod_rewrite.
In a nutshell, as #Cnu as mentionned, the problem very few resources on the internet touch on is the fact that your apache configuration must contain an AllowOverride FileInfo directive for wordpress rewrites to work without /index.php/.
Since Apache 2.4, AllowOverride default setting is "None", which is often a roadblock in making "pretty urls" work (in this case ditching the index.php). As #cnu mentionned, you should read carefully this resource : https://wordpress.org/support/article/using-permalinks/.
Make sure to have mod_rewrite enabled
-> (to be sure create an info.php you will remove later containing the line <?php phpinfo();?>) at the root of your blog and call https://domainofyourb.log/info.php)
Make sure your .htaccess is writable by wordpress. (permission and ownership should be allowing your webserver (often with the username "apache") to edit the file.
Change your wordpress permalinks settings, and check that .htaccess file is correctly written.
Check that your apache configuration (etc/httpd/conf/httpd.conf in some linux distros) contains the directive AllowOverride FileInfo within your blog's <Directory></Directory> section
Options directive to FollowSymLinks should be the default, but if Options directive is mentionned, add FollowSymLinks for good measure.
when all that is done, don't forget to restart your Apache server. (sudo service httpd restart in my case, ymmv).
P.S : wrote this answer because I can't comment (don't have rep) on cnu's answer, and wanted to correct 1. allowoverride doesn't need to be set to ALL, it can be set to simply "FileInfo", 2. update the link to wordpress doc, and 3. provide background on the change in apache 2.4 that causes this issue.
Go to admin page, Dashboard -> Settings -> Permalink Settings -> Custom Structure, select /%postname%/ or, /%year%/%monthnum%/%day%/%postname%/ up to you.

Wordpress issue after migration

Have changed to a new server and have migrated a number of Wordpress sites. After migration, I found that the menu links were no longer working. The content is there however.
I deleted the htaccess file and changed the permalinks to the default setting 'plain'. That worked fine. However, now my website is working with menu links like domain.com/?page_id=29.
On the old server, I have always been using the format domain.com/post_name. So I deleted the htaccess file again and changed the permalink to post_name, but clicking on the link in the menu always gives me a 404 error. Checked a phpinfo() and mod_rewrite is enabled.
The htaccess file right now is:
# 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>
How to get back working menu links when permalinks are set to postname?
On Linux, in order to relax access to the document root, you should edit the following file: /etc/httpd/conf/httpd.conf
In case you are on Ubuntu, edit the file /etc/apache2/apache2.conf (here we have an example of /var/www)
And depending on what directory level you want to relax access to, you have to change the directive
AllowOverride None
to
AllowOverride All
So, assuming you want to allow access to files on the /var/www/html directory, you should change the following lines from:
<Directory "/var/www/html">
AllowOverride None
</Directory>
to
<Directory "/var/www/html">
AllowOverride All
</Directory>
Reference Docs for you:
https://codex.wordpress.org/Using_Permalinks
I take it when you say the menu lnks stopped working again you mean to say that the link changes fine to the new permalink format of http://domain/post_name right?
If so you're issue lies in mod_redirect. Either in the .htaccess in the docroot (turning it on and having correct redirect rules) or it could in your apache web server config file. perhaps apache doesn't even have mod_redirect enabled. if it's a CPANEL server mod_redirect is likely to be enabled however.
Issue can be the path of the files as well. Do you migrate the account with same username and same path as of the old server ?
If path is different than the old server, take a mysql dump of the db, look for the path and change them to the correct new path.
If paths are same, then you could fix this issue by just resetting the permalinks i.e first change the permalinks to some other one than the current one and save and then immediately change back to old one which was in use earlier and then again save it. This have worked for me in past.

Wordpress permalink structure change issue

I have seen some other posts on SO about this issue, however none of the suggested solutions did work for me, so I repost.
After changing my permalink structure to /%postname%/, none of the links is working. I get the following 404:
Not Found
The requested URL /my-post-name/ was not found on this server.
Apache/2.2.20 (Ubuntu) Server at mysite.com Port 80
When I get back to the default permalink structure it starts to work again, but I want to have /%postname%/ structure anyways.
My .htaccess file's chmod is 777.
After updating my permalink structure to /%postname%/, the .htaccess file generated by Wordpress is the following:
# 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
Any thoughts?
Edit:
I tried to change permalink structure to the following:
/index.php/%postname%/
and it happily worked. However, the problem is now, not surprisingly, the links are in the following form:
www.mysite.com/index.php/my-page.com
My question is how can I remove index.php from my links. When I remove it from the permalink structure (i.e., /%postname%/), my links no longer work.
PS: Instead of using blog entries I use only pages in my site. If it is necessary my site is: mll.sehir.edu.tr.
There are many ways how you can fix this issue, if you know the root of the issue.
Problem 1
Firstly, it may be a problem with your apache not having the mod_rewrite.c module installed or enabled.
For this reason, you would have to enable it as follows
Open up your console and type into it, this:
sudo a2enmod rewrite
Restart your apache server.
service apache2 restart
Problem 2
You may also, in addition to the above, if it does not work, have to change the override rule from the apache conf file (either apache2.conf, http.conf , or 000-default file).
Locate Directory /var/www/
Change the Override None to Override All
Problem 3
If you get an error stating rewrite module is not found, then probably your userdir module is not enabled. For this reason you need to enable it.
Type this into the console:
sudo a2enmod userdir
Then try enabling the rewrite module if still not enabled (as mentioned above).
To read further on this, you can visit this site: http://seventhsoulmountain.blogspot.com/2014/02/wordpress-permalink-ubuntu-problem-solutions.html
Sounds like a problem with symlinks on your server. Try this in your .htaccess and also please change it to 644 after making the change:
Options +FollowSymlinks
RewriteEngine on
# 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 had the same problem but i am using other url structure /%category%/%postname%/
The problems with de 404 error is because even if you set a certain structure, wordpress is always trying to create the urls with the word "category" on the url.
Try to type your urls like this: yoursite.com/category/postname, if you are not getting any error now is because we are close to resolving the error. Now try to install this wordpress plugin http://wordpress.org/extend/plugins/no-category-base-wpml/ to remove the "category" base from urls
Let me know about your progress
Replace and try your .htaccess with this:
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^hostname.com$
RewriteRule ^(.*)$ http://www.hostname.com/$1 [R=permanent,L]
I got this issue whenever i try to enable my site's permalink to mod_rewrite: "Pretty Permalinks". My site is one instance on AWS EC2.
404 Errors
Page Not Found
The requested URL .... was not found on this server.
Apache/2.4.7 (Ubuntu) Server at mydomain.com Port 80
I tried all above methods, but not being fixed.
At last, I checked the /etc/apache2/sites-available/wordpress.conf, I found I used public IP address assigned to each instance by AWS. Once I change it to the current mydomain.com, it's working.
Sometimes, wordpress.conf would be locked by httpd (web serser), we need to stop and start it after edit. We also need to use: sudo service apache2 stop/start so as wordpress.conf could be reload again.
Hope my experience could help others.

Permalinks in Wordpress - Page not found

I've been searching for hours but haven't found anything that seems to be able to solves this issue.
Here's the scenario:
I'm making a wp theme based on the "Twenty Eleven" theme. Everything went fine til I decided to change the urls to permalinks. The only page being displayed is the static page that I have defined earlier.
I have set up the htacces file. In fact, WP did it automatically. Everything works if I switch back to the default setting, but, for SEO, I would rather use the permalinks option.
Here is my htaccess file (it is on my WP installation folder):
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /mysite/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /mysite/index.php [L]
</IfModule>
# END WordPress
I have seen this post wordpress .htaccess with permalinks but nothing there could help me. Any help would be very nice.
UPDATE : Things I have tried already:
Delete pages and create again.
Access the permalink field on wp_options (db) and setting the value to blank and set the permalink option in the admin again.
I´m running it on windows 7 through an apache2 installation of Zend Server.
I thought it was a problem related to my localhost environment, so I put the site online. No luck at all. I'm assuming that wordpress can´t change permalinks to a more friendly url type when you set a static front page. What a shame.
For those using apache. You will need to
Ensure you have .htaccess in root path of the site you are hosting. Example /var/www
Update the /etc/apache2/sites-available/default
From
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
To
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
Hope this helps someone
If editing apache2's default configuration and Wordpress' .htaccess files don't help the reason could simply be that apache2's rewrite module is not enabled. This is usually the case for those who install apache2 themselves. Wordpress needs apache2's rewrite module enabled to support permalink edits. If, like me, you'd rather not edit conf files by hand, apache2's rewrite module can be enabled by running these commands as root (I'm using Ubuntu 18.04, so these commands might be different in distros that aren't based on Ubuntu or Debian):
a2enmod rewrite
and restart the apache2 service by running:
systemctl restart apache2
or
service apache2 restart
If you're running Ubuntu 18.04, you can check out all available apache2 modules under /etc/apache2/mods-available and see what modules are enabled by listing the files under /etc/apache2/mods-enabled.
I don't know if you have found the solution to it, but I solved this problem by simply turning on LoadModule rewrite_module modules/mod_rewrite.so in httpd.conf file.
Also see Permalinks on WordPress (Amazon EC2)
I had the same problem, but the author in the above link suggested to do three things (it worked for me!):
Go to /etc/httpd/conf and edit httpd.conf
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
Change also AllowOverride if it is set to None
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride All
I you haven’t created it yet, place in the root directory of your wordpress
installation a .htaccess file with the following contents:
# 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
There are two 'Directory' sections in the httpd.conf file.
One is for root folder and another for htdocs folder.
You must edit both fields to make WordPress pages work again.
Hope it helps.
This worked for me like #Skillachie wrote BUT be also sure to include those settings in the 000-default-SSL.conf file if you use SSL!
<Directory /var/www/PATH>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>

URL rewriting doesn't work

There are some pages in this format:
http://www.saglikkosesi.net/soru-ve-yanitlari-goster?page=2
I want them to appear in this format:
http://www.saglikkosesi.net/soru-ve-yanitlari-goster/page/2
I used the following code in .htaccess:
Options +FollowSymLinks
RewriteEngine on
RewriteRule soru-ve-yanitlari-goster/page/(.*)/ soru-ve-yanitlari-goster?page=$1
RewriteRule soru-ve-yanitlari-goster/page/(.*) soru-ve-yanitlari-goster?page=$1
Nothing changed. What can I do to fix this? (I use WordPress platform for my web site. But I can't use permalink feature for this redirection as this pages are external pages and I can't control them via WP admin.)
Are you sure that .htaccess files are enabled by your Apache configuration?
By the way, you do that by setting AllowOverride All in the <Directory section of your httpd.conf file.
You need RewriteCond to access the query string and capture the relevant part:
RewriteCond %{QUERY_STRING} ^page=(\d+)
RewriteRule ^/soru-ve-yanitlari-goster$ soru-ve-yanitlari-goster/page/%1?

Resources