I have set a post to private on a WordPress multisite so users should be redirected to a 404 page. The permalink of this post is .
Now WordPress seems to redirect requests to event
to event-30-01-2016
. WordPress seems to focus on the lower number after the event
string. Example: it will prioritise event-29-05-2015
over event-30-05-2015
.
I want to keep the URLs for posts like event-*
but I want event
to redirect to 404 since I kind of disabled the page.
My settings on /wp-admin/options-permalink.php
are set to Post name
.
I don't have any special rewriteRules in .htaccess
for events.
This is my .htaccess
:
# BEGIN WordPress
RewriteEngine on
RewriteBase /
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]
# END WordPress
Is there maybe a hook that I could use in order to disable this kind of redirection?
This question already has answers here: How to prevent automatic redirection of 404 errors and "incorrect" URLs? (3 answers) Closed 6 years ago.I have set a post to private on a WordPress multisite so users should be redirected to a 404 page. The permalink of this post is http://local.website/en/event
.
Now WordPress seems to redirect requests to event
to event-30-01-2016
. WordPress seems to focus on the lower number after the event
string. Example: it will prioritise event-29-05-2015
over event-30-05-2015
.
I want to keep the URLs for posts like event-*
but I want event
to redirect to 404 since I kind of disabled the page.
My settings on /wp-admin/options-permalink.php
are set to Post name
.
I don't have any special rewriteRules in .htaccess
for events.
This is my .htaccess
:
# BEGIN WordPress
RewriteEngine on
RewriteBase /
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]
# END WordPress
Is there maybe a hook that I could use in order to disable this kind of redirection?
To completely disable this feature, use this code, which I got from here.
remove_action( 'template_redirect', 'redirect_canonical' );
To only disable it for URL addresses that contain the string 'event', use this code:
add_filter( 'redirect_canonical', 'disable_redirect_canonical_for_event', 2, 10 );
function disable_redirect_canonical_for_event( $redirect_url, $requested_url ) {
if ( strpos( $requested_url, 'event' ) !== false ) {
return false;
}
return $redirect_url;
}
remove_action('template_redirect', 'redirect_canonical');
helped me – zyrup Commented Nov 28, 2018 at 20:42