HTTP 404 with Post name permalink
Asked Answered
T

8

17

Okay so I've just create the first page on this site. It works when I use the default permalink settings.

If I change the permalink settings to use Post name, then I get an HTTP 404.

I'm not sure what's gone wrong or if I've broken anything. Can anyone help me fix?

The site is hosted on apache.

Page exists, link is broken

Thorium answered 17/6, 2014 at 13:35 Comment(0)
R
36

Are you using XAMPP or MAMP? There are a couple of common hiccups with those environments, taken from the WordPress Codex: Fixing Permalink Problems

Users of XAMPP (Windows): Some versions of XAMPP do not enable mod_rewrite by default (though it is compiled in Apache). To enable it — and thus enable WordPress to write the .htaccess file needed to create pretty permalinks — you must open apache/conf/httpd.conf and uncomment the line LoadModule rewrite_module modules/mod_rewrite.so (i.e., delete the hash/pound sign at the front of the line).

Users of WAMP (Windows): Some versions of WAMP (all versions?) do not enable mod_rewrite or permit following SymLinks by default. To enable the required functionality navigate to the apache/conf/httpd.conf file, open with a text editor and uncomment the line LoadModule rewrite_module modules/mod_rewrite.so (i.e., delete the hash/pound sign at the front of the line). Then further down in the same file there is a section that starts with the line "Options FollowSymlinks". Change the second line in that section from "AllowOverride none" to AllowOverride all. Save edited httpd.conf and restart all WAMP modules. Your permalinks should now work.

You might also see Permalinks without mod_rewrite if your sandbox doesn't have mod_rewrite available.

Apache

If you are using Apache there are usually two other culprits to broken permalinks: .htaccess isn't being generated (because of permissions settings) or Apache's AllowOverride directive isn't enabled.

First, if you SSH into your server, do you see a generated .htaccess file in the root? If not, WordPress might not have permissions to write that file. It's also possible the file does exist, but that WordPress cannot edit it. In either case, you can chmod that file (and create it if it doesn't exist) to 666.

Next, ensure your Apache config has the following settings:

  <Directory />
    Options FollowSymLinks
    AllowOverride All
 </Directory>

Finally, read through the Fixing Permalink Problems section of the WordPress Codex. There are several other tips and suggestions on why permalinks might not work.

Ranna answered 17/6, 2014 at 14:3 Comment(8)
This is hosted on apacheThorium
@Thorium Sorry, I missed that. I updated my answer, hopefully that helps.Ranna
You didn't miss it, I thought it went without saying so didn't include that info. Did add it in now thoughThorium
Okay the .htaccess should be in the root directory for WP or in the root directory for the theme?Thorium
@Thorium It should be in the root of the site itself (and it looks like you have WordPress running at your site root). It should be at the same level as the first WordPress index.php file.Ranna
I can't see a .htaccess file in FileZilla so I sent info to the server adminThorium
That was it. There wasn't actually a .htaccess file anywhere so added one, set permissions and then WP did the restThorium
This fixed it for me, after I stopped and restarted Apache in my XAMPP.Isosceles
W
15

In my case, firstly I had to update the .htaccess file inside my website root folder:

# 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

WordPress does this automatically if it has write permission. Otherwise it'll complain it can't write to it, and give the above code sample so you can manually update the .htaccess.

After that, I edited the apache2.conf file. In Linux, it resides in /etc/apache2/apache2.conf, there will be a section like this:

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

Change AllowOverride None to AllowOverride FileInfo.

Finally, execute the following commands:

sudo a2enmod rewrite
service apache2 restart

All these steps were necessary in order to work.

Whacky answered 27/12, 2017 at 13:3 Comment(1)
AllowOverride FileInfo was my missing piece.Sparklesparkler
L
1

found this post on another site helped many people already

I finally managed to solve the problem! The solution: I was using a custom permalink structure http://kyl.fi/%category%/%postname%/. I removed the trailing slash (i.e. the last /) and voila. However, I'm quite sure I used a permalink structure with the trailing slash before without any problems, so I'm still confused and would be interested the hear more about this issue if somebody has an explanation.

All the standard permalinks have a trailing / in there.

Lanlana answered 26/6, 2014 at 9:42 Comment(0)
H
1

In my case, I am using the NGINX web browser with my WordPress installation. The fix is to add the following code snippet to the NGINX Directives:

location / { try_files $uri $uri/ /index.php?$args; } # Add trailing slash to */wp-admin requests. rewrite /wp-admin$ $scheme://$host$uri/ permanent; location ~* \.(jpg|jpeg|png|gif|css|js|ico)$ { expires max; log_not_found off; }

If you are using the excellent (open source) ISPconfig.org CPanel substitute, then go to your Sites page, under the Options tab, enter the above code snippet for NGINX Directives. ISPconfig has a feature to add common code snippets for quick access under the Options tab.

After making the above fix, I was able to use any of WordPress' Permalinks options.

Hess answered 28/9, 2016 at 6:27 Comment(1)
this is the only fix that worked for me after migrating my wp database from one server to another manually.Infuse
T
1

in centos 8 and apache 2.4 look in /etc/httpd/conf.d in your site .conf file add AllowOverride All, example like this

<Directory /path/to/site>
     #add the following setting to allow .htaccess in your web dir to work
     AllowOverride All

</Directory>

MY 80 LISTEN PORT

    #Listen 80
<VirtualHost *:80>
    DocumentRoot "/var/www/mysite.com"
    ServerName www.mysite.com

    # Other directives here
    

        <Directory "/var/www/mysite.com">
                Options FollowSymLinks
                AllowOverride All
        </Directory>
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.mysite.com [OR]
RewriteCond %{SERVER_NAME} =mysite.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

MY SSL VIRTUAL HOST:

<IfModule mod_ssl.c>
<VirtualHost *:443>
    DocumentRoot "/var/www/mysite.com"
    ServerName www.mysite.com

    # Other directives here
    <Directory "/var/www/mysite.com">
                Options FollowSymLinks
                AllowOverride All
        </Directory>
ServerAlias mysite.com
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/mysite.com/fullchain.pem
SSLCertificateKeyFile /live/mysite.com/privkey.pem
</VirtualHost>
</IfModule>

Restart apache service. Check your .htaccess (in my site the .htaccess is located in /var/www/mysite.com My .htaccess

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteRule ^helloWorld/?$ /index.php [NC,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

look helloWorld rewrite rule. If you invoke url www.mysite.com/helloWorld and the browser show your homepage, the configuration is working and the permalink path to site works.

Thompson answered 3/2, 2021 at 13:57 Comment(0)
C
0

Tested Working Solution:

in your apache2 config file for example:

/etc/apache2/sites-enabled/000-default.conf or mysite.conf etc ..

Make sure you have set param and not empty: ServerName www.example.com or 123.212.333.111

Also make sure You have set directory rules as below (Your rewrite rules may not have taken effect in the .htaccess hence you put it here and try finding out Why .htaccess does not work .htaccess not working apache):

<Directory /var/www/html>
       Options Indexes FollowSymLinks MultiViews
       AllowOverride All
       Order allow,deny
       allow from all

       RewriteEngine On
       RewriteBase /
       RewriteRule ^index\.php$ - [L]
       RewriteCond %{REQUEST_FILENAME} !-f
       RewriteCond %{REQUEST_FILENAME} !-d
       RewriteRule . /index.php [L]
</Directory>
Carryingon answered 22/6, 2018 at 16:37 Comment(0)
C
0

Must be 2 point check: 1. Add code to .htaccess file:

# 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
  1. And Permission of .htaccess file, must be: 644
Crematorium answered 1/11, 2018 at 19:32 Comment(0)
P
0

My solution was add this code in /etc/apache2/sites_available/000-default.conf

<Directory "/var/www/mysite.com">
    Options FollowSymLinks
    AllowOverride All
</Directory>

I'm on Apache 2.4.46 (Ubuntu) Thank you

Pennyweight answered 5/2, 2021 at 13:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.