This question already has answers here: How to prevent automatic redirection of 404 errors and "incorrect" URLs? (3 answers) Closed 6 years ago.admin管理员组文章数量:1130349
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?
Share Improve this question edited Nov 28, 2018 at 5:43 butlerblog 5,1413 gold badges28 silver badges44 bronze badges asked Nov 27, 2018 at 21:59 zyrupzyrup 1034 bronze badges 3 |1 Answer
Reset to default 0To 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;
}
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 .
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?
Share Improve this question edited Nov 28, 2018 at 5:43 butlerblog 5,1413 gold badges28 silver badges44 bronze badges asked Nov 27, 2018 at 21:59 zyrupzyrup 1034 bronze badges 3- Try this wordpress.stackexchange/questions/71927/… – Nikolay Commented Nov 28, 2018 at 18:42
-
@Nikolay oh.. thank you a lot! I'll add the script in the answer that helped me. Or maybe you would like to answer the question?
remove_action('template_redirect', 'redirect_canonical');helped me – zyrup Commented Nov 28, 2018 at 20:42 - You don’t want to completely remove canonical redirection! Check for your specific case and only remove it for those requests. – Milo Commented Nov 28, 2018 at 22:52
1 Answer
Reset to default 0To 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;
}
本文标签: multisiteDisable quotsimilar permalinkquot redirect
版权声明:本文标题:multisite - Disable "similar permalink" redirect 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749143267a2322568.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


remove_action('template_redirect', 'redirect_canonical');helped me – zyrup Commented Nov 28, 2018 at 20:42