Wordpress: .htaccess file and rewrite rules: Custom Post Type (CPT) pages return in 403 / 404 errors

3 weeks ago 26
ARTICLE AD BOX

while many say: CPTs do not impose unusual or specific server hardware requirements - i think that some standard WordPress hosting is sufficient for most use cases,

i have the queswtion: what are the conditions - that you think are most impotant!?

BTW; regarding the PHP Environment and for the Condition: i guess that we ensure the server runs a recent, supported version of PHP for optimal performance and security.

regarding URL Rewriting (Permalinks): CPTs use WordPress rewrite rules to create clean, user-friendly URLs (permalinks), such as on my_site.com.

Condition: The web server (usually Apache or Nginx) must be configured to process the WordPress .htaccess file or equivalent rewrite rules correctly. If CPT pages return 404 errors, this often indicates a server-side rewrite configuration issue, which can usually be fixed by simply re-saving the permalink settings in the WordPress admin area.

What if the created urls https://www.my_site.com/cpt/addsmart/

https://www.my_site.com/cpt/ are not (!) accessible!

well - belive me: the behavior is funny.

the both urls https://www.my_site.com/cpt/addsmart/

https://www.my_site.com/cpt/ they both throw a access denied

btw: i have written the following to the .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

but i guess that this is not processed - du to some configuration-things.

update: see some more inghts

and see this - what i have added to the .htaccess

Permalink-Struktur: Plain WordPress does not create any Rewrite-Regeln all the "pretty URLs" run over: mod_rewrite (Apache) or Nginx Rewrite Rules but well my server Server says: ❌ „these URLs could not be executed“

see some insights into the configuration:

conclusio: PHP & Apache are corretly built, mod_rewrite seems to be loaded

Configure Command:

'./configure' '--prefix=/usr/local/php-8.4.14' '--with-apxs2=/usr/local/apache/bin/apxs' '--without-snmp' '--disable-ipv6' '--enable-sigchild' '--with-pear' '--with-mysql-sock=/var/run/mysql/mysql.sock' '--enable-calendar' '--with-zlib' '--enable-mbstring' '--with-pdo-mysql' '--with-mysqli' '--disable-mbregex' '--with-openssl=/usr/local/' '--enable-shmop' '--enable-sysvshm' '--with-pdo-sqlite' '--enable-gd' '--with-mm=/usr/local/mm/' 'OPENSSL_CFLAGS=-I/usr/local/include' 'OPENSSL_LIBS=-L/usr/local/lib -lssl -lcrypto' '--with-openssl-argon2' '--enable-static=NO' '--with-curl=/usr/local/' 'CFLAGS= -O2 -march=native -Wno-erro '

Loaded Modules:

'http_core mod_authn_file mod_authn_dbm mod_authn_socache mod_authz_host mod_authz_groupfile mod_authz_user mod_authz_core mod_access_compat mod_auth_basic mod_auth_digest mod_socache_shmcb mod_watchdog mod_ratelimit mod_reqtimeout mod_filter mod_deflate mod_mime mod_log_config mod_env mod_mime_magic mod_expires mod_headers mod_usertrack mod_setenvif mod_version mod_session mod_session_cookie mod_ssl prefork mod_unixd mod_autoindex mod_dir mod_alias mod_rewrite mod_php'

update 2 well - some more notes:

mod_rewrite ✔ loaded

WordPress Plain-Links ✔ running well

Pretty Permalinks ❌ 403

Theme - tt3 tt4 tt5 - each time the same behavior

Plugins - they do not play a vital role

it seems to be the only missing thing:

❌ Apache blocks .htaccess or the Paths

well hmm - that could mean:

case 1: AllowOverride None

Apache does not read the .htaccess allthough the file exists.

example - problematic:

<Directory /var/www/html> AllowOverride None </Directory>

➡️ WordPress cannot activate some (any) Rewrite-rules

➡️ Apache replies with 403 Access denied

case 2: Restrictive <Directory> or <Location>-Rules

for example

<Directory />

Require all denied

</Directory>

or:

Require all denied

➡️ only explicit allowed files were visible (index.php?p=123)

➡️ virtual Paths (/my_slug/) were blocked

and - some more insights:

Why ?p=123 is showed (important point - !!)

?p=123:

will be given directly to index.php - it is "handed over" to the index.php

no Rewrite

no test of the path

/my_slug/:

Apache checks:

a. could this path be "True" - could this path exist?

b. are there any rules?

is .htaccess allowed to "do "anything" here?

👉 and exactly here the 403 comes ....

well - i need to fix this - i definitly have to "fix" this and i need to get rid of these issues

Diagnosis (definitive):

Your server is blocking all "path-based URLs" (/foo, /edih/, /sample-post/) at the Apache level before WordPress takes action.

+------------------------+-----------------+------------------------------------+ | Test | result | meaning | +------------------------+-----------------+------------------------------------+ | /?p=POST_ID | ✔ visible | PHP + WordPress OK | | /permalink-test/ | ❌ Access denied | Rewrite-URLs blocked | | /this-should-not-exist | ❌ Access denied | Apache blockt Patgs | | /wp-content/ | blank | Directory Listing deaktiviert (ok)| | /wp-includes/ | ❌ Forbidden | closed (normal) | | /rewritetest.php | ❌ Access denied | critical | +------------------------+-----------------+------------------------------------+
Read Entire Article