Disabilita il completamento automatico dell'URL di Wordpress
-
-
Una soluzionetestata chenon disabilita l'intero sistema URL canonicoma disabilita solo laparte "indovinare" del completamento automatico è delineata [qui] (http://wordpress.stackexchange.com/a/144970/51898)A tested solution that does not disable the whole canonical URL system but only disables the autocomplete "guessing" part is outlined [here](http://wordpress.stackexchange.com/a/144970/51898)
- 0
- 2014-05-20
- Hauke P.
-
4 risposta
- voti
-
- 2013-03-24
Credo che sia lafunzione
redirect_canonical
collegata atemplate_redirect
. Dovrestiesserein grado di disabilitarlo con:remove_filter ('template_redirect','redirect_canonical');
Ma dovresti davveropensare se vuoifarloperché è abbastanza complicatoe svolge alcuneimportantifunzioni SEO:
Reindirizzai linkin entrata all'URL correttoin base all'URL del sito.
Imotori di ricerca considerano www.somedomain.come somedomain.com due URL diversi quandoentrambi vannonella stessaposizione. Questo SEO ilmiglioramentoimpedisce lapenalitàperil contenuto duplicato reindirizzandotutto linkin entrata all'uno o all'altro.
Impedisceil reindirizzamentoperfeed,trackback,ricerche,popup di commenti, e URL di amministrazione. Non reindirizza su supporti chenon supportanopermalink IIS 7,anteprime dipagine/post,amministrazione WP,trackback,robots.txt,ricerche, o su richieste POST.
Tenterà anche ditrovareil collegamento corretto quando un utenteinserisce un URL chenonesistein base alla queryesatta di WordPress. Ciproveròinvece per analizzare l'URL o la queryneltentativo diindividuare lapagina corretta vai a.
http://core.trac.wordpress.org/browser/tags/3.5.1/wp-includes/canonical.php#L13
Quanto segue potrebbe interrompereil completamento automatico senzainterferire conil componente SEO,manonpossoprometterlo. Il codice è appena statotestato poichénon homai desiderato disabilitarlo. Dovrei davvero studiare
redirect_canonical
peressere sicuro di qualsiasi cosa.funzione kill_404_redirect_wpse_92103 () { if (is_404 ()) { add_action ('redirect_canonical','__ return_false'); } } add_action ('template_redirect','kill_404_redirect_wpse_92103',1);
I believe that is the
redirect_canonical
function hooked totemplate_redirect
. You should be able to disable it with:remove_filter('template_redirect', 'redirect_canonical');
But you should really think about whether you want to do that as it is fairly complicated and performs some important SEO functions:
Redirects incoming links to the proper URL based on the site url.
Search engines consider www.somedomain.com and somedomain.com to be two different URLs when they both go to the same location. This SEO enhancement prevents penalty for duplicate content by redirecting all incoming links to one or the other.
Prevents redirection for feeds, trackbacks, searches, comment popup, and admin URLs. Does not redirect on non-pretty-permalink-supporting IIS 7, page/post previews, WP admin, Trackbacks, robots.txt, searches, or on POST requests.
Will also attempt to find the correct link when a user enters a URL that does not exist based on exact WordPress query. Will instead try to parse the URL or query in an attempt to figure the correct page to go to.
http://core.trac.wordpress.org/browser/tags/3.5.1/wp-includes/canonical.php#L13
The following might kill the autocompletion without messing with the SEO component, but I can't promise that. The code is barely tested as I have never wished to disable this. I'd really have to study
redirect_canonical
to be sure of anything.function kill_404_redirect_wpse_92103() { if (is_404()) { add_action('redirect_canonical','__return_false'); } } add_action('template_redirect','kill_404_redirect_wpse_92103',1);
-
Ho aggiunto questoframmento di codice allafine delmiofile/wp-includes/canonical.phpe i reindirizzamenti continuano.Stofacendo qualcosa di sbagliato?Qualcun altronon èin grado di disabilitare questo comportamento?I added this code snippet to the end of my /wp-includes/canonical.php file and the redirects are still happening. Am I doing something wrong? Anyone else unable to disable this behaviour?
- 0
- 2019-06-04
- user1380540
-
@ user1380540nonmodifichii file core.questo andrebbe a untemafunctions.php oa unplugin.@user1380540 you don't edit core files. this would go to a theme functions.php or to a plugin.
- 0
- 2020-07-16
- Michael Rogers
-
- 2014-07-28
Sembraterribilmenteirresponsabile che questo "indovinare" avvenga automaticamente.Sareimoltopiù aperto se cifosse qualchemezzoper definire qual è lapagina corretta a cui andare.
Honumerosepagine che sono costruite come una sequenzae questa auto-ipotesi sta scegliendoerroneamente di rispondere conpagine che sitrovano (inmodo casuale?) da qualchepartenella sequenza,al contrario dellapaginainiziale.
AGGIORNAMENTO: questo è un comportamentonotoe vienepresoin considerazione qui: https://core.trac.wordpress.org/ticket/16557
This seems terribly irresponsible, to have this "guessing" occur automatically. I would be much more open to it if there were some means of defining which was the correct page to go to.
I have numerous pages that are built as a sequence, and this auto-guessing is incorrectly choosing to respond with pages that are (randomly?) somewhere in the sequence, as opposed to the starting page.
UPDATE: This is known behavior, and is being considered here: https://core.trac.wordpress.org/ticket/16557
-
- 2017-08-02
In seguito alla risposta di FitPM,è stato creato unplug-in che disabilitail comportamento di auto-indovinazione.
Funzionabene perme su Wordpress 4.8 dal 2 agosto 2017. Ilplug-in è qui: https://wordpress.org/plugins/disable-url-autocorrect-guessing/
As a follow up to FitPM's answer - a plugin has been created that disables the auto-guessing behavior.
It works fine for me on Wordpress 4.8 as of August 2, 2017. The plugin is here: https://wordpress.org/plugins/disable-url-autocorrect-guessing/
-
- 2020-05-13
Unanota: se si disabilita redirect_canonical (ades. con
remove_action('template_redirect', 'redirect_canonical');
),collegamenti casuali come https://tld.com/some-random-string/blogpost funziona (il contenuto di https://tld.com/real-category-slug/blogpost vienemostrato).Se vuoiimpedirloe restituire 404 su quegli URL casuali,usa qualcosa come
add_filter( 'redirect_canonical', function( $redirect_url ) { $url = 'http'.((isset($_SERVER['HTTPS'])&&$_SERVER['HTTPS']!=='off')?'s':'').'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; if( $redirect_url !== $url ) { global $wp_query; $wp_query->set_404(); status_header( 404 ); nocache_headers(); } return false; });
One note: If one disables redirect_canonical (e.g. with
remove_action('template_redirect', 'redirect_canonical');
), random links like https://tld.com/some-random-string/blogpost also work (the content of https://tld.com/real-category-slug/blogpost is shown).If you want to prevent that and return 404 on those random urls, use something like
add_filter( 'redirect_canonical', function( $redirect_url ) { $url = 'http'.((isset($_SERVER['HTTPS'])&&$_SERVER['HTTPS']!=='off')?'s':'').'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; if( $redirect_url !== $url ) { global $wp_query; $wp_query->set_404(); status_header( 404 ); nocache_headers(); } return false; });
Di recente honotato che Wordpresstenta di completare automaticamente un URL quandonon vieneinviatonella suainterezza.Peresempio.Ho un URL delpost simile a questo:
Se cercoil seguente URL:
Vedo che l'URL èinviato a Wordpressma che Wordpress staeseguendo un reindirizzamento 301 a
http://www.mysite.com/some-post-title
.Comeposso disabilitare questo comportamento?