Ireneo Crodua
Ireneo Crodua

Reputation: 398

change permalinks to 'Postname' cause Page Not Found

I have a query to fetch all post from a custom post type device and I want to display 3 post per page. using the next and previous link, I able to navigate the next page where another 3 post can see. it work perfectly with the default permalink which is

  //the default permalink of wordpress
http:mywebsite/?p=123

and I need to change it into Post name for SEO purposes which is like this:

http:mywebsite/sample-post/

and then suddenly the problem appear.

I've searching and reading more blog/article but I can't find any helpful suggestion. I'm so stuck with this problem it give me a headache.

by the way I used this query:

   <?php
     if (have_posts()) : {
     $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
     query_posts('showposts=3&post_type=advice'.'&paged='.$paged);} ?>

      <ul class="adviceLandingPage">

      <?php while(have_posts()) : the_post(); ?>

       <li>
         <span><?php the_title(); ?></span>
         <span><?php $excerpt = get_the_excerpt(); echo string_limit_words($excerpt,20); ?></span>

       </li>

       <?php endwhile; ?>
          <li class="navigation">
             <?php posts_nav_link(); ?>
          </li>
       </u>
     <?php endif; ?>

thank you for any suggestion.

Edit:

when I navigate to the next page, where I assume to see the next 3 post, this is the error Page not found.

and this is the .htaccess after changing the permalink to %postname%

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /bryan/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /bryan/index.php [L]
</IfModule>

# END WordPress

Upvotes: 9

Views: 26010

Answers (9)

TechBrad
TechBrad

Reputation: 87

I ran into this exact scenario after updating to https/SSL using a LetsEncrypt cert.

The instructions in the URL below are valid, however instead of updating 000-default.conf, I had to update the ssl conf file with the "AllowOverride All".

/etc/apache2/sites-available/domainname-le-ssl.conf

https://sachinparmarblog.com/fixing-permalinks-on-wordpress-to-use-postname/

Upvotes: 0

GaBo
GaBo

Reputation: 31

I solved that problem in Settings-> Permalinks check Post name and copying the content of .htacces, which is shown when you save. Access the web hosting and modify the .htaccess and paste the content and save

Upvotes: 0

Ruhith Udakara
Ruhith Udakara

Reputation: 2452

this happens to me when I didn't give write access to the .htaccess file. changing permission of .htaccess file solved my problem

Upvotes: 0

Diyen Momjang
Diyen Momjang

Reputation: 1851

Run the following commands

NB: The $ Is not part of the commands

$ sudo a2enmod rewrite

$ cd /var/www/html

$ ls -al

$ sudo touch .htaccess

$ sudo nano .htaccess

Modify your .htaccess file to look the snippet above

# 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

$ sudo chmod 644 .htaccess

$ sudo nano /etc/apache2/sites-available/000-default.conf

Make sure the AllowOverride All is set

<Directory "/var/www/html">
    AllowOverride All
</Directory>

$ sudo /etc/init.d/apache2 restart

See the link below for more on this.

https://sachinparmarblog.com/fixing-permalinks-on-wordpress-to-use-postname/

Upvotes: 7

Lalit Kharat
Lalit Kharat

Reputation: 1

If you are using nginx and want to change wordpress permlinks from plain to Post name simply add following line into nginx file

location / {
  try_files $uri $uri/ /index.php?q=$uri&$args;
}

and if your wordpress is install in specific folder example /blog then add this

location / {
  try_files $uri $uri/ /blog/index.php?q=$uri&$args;
} 

Upvotes: -1

dstark
dstark

Reputation: 21

Also check the httpd.conf file and make sure AllowOverride is All for the directory that holds the .htaccess file

Upvotes: 1

Nanni Campos
Nanni Campos

Reputation: 9

I found a fix.

Go into the WordPress admin dashboard, go to:

“Settings” > “Permalinks” > “Common settings”, and set the radio button to “Custom Structure”

, and paste into the text box:

/index.php/%year%/%monthnum%/%day%/%postname%/

, and click the Save button.

Upvotes: 0

shahoo
shahoo

Reputation: 101

To fix this problem, do the following steps:

  1. find the httpd.conf file on the Web server
  2. Find the code LoadModule rewrite_module modules / mod_rewrite.so
  3. removing the # in front of it
  4. find the code AllowOverride none and convert to AllowOverride all

It's as simple as delicious :)

Upvotes: 10

jvargas
jvargas

Reputation: 9

not sure if you already fixed this, but usually all you need to do is flush the db, login to your site a go to permalinks and just make a change and save it and if that doesn't help

read this: http://codex.wordpress.org/Using_Permalinks

Upvotes: 0

Related Questions