{"id":5093,"date":"2018-10-28T17:12:45","date_gmt":"2018-10-28T17:12:45","guid":{"rendered":"https:\/\/musilda.cz\/?p=5093"},"modified":"2018-10-28T17:12:45","modified_gmt":"2018-10-28T17:12:45","slug":"jak-opravit-chybu-404-ve-wordpressu","status":"publish","type":"post","link":"https:\/\/affinite.io\/cs\/jak-opravit-chybu-404-ve-wordpressu\/","title":{"rendered":"Jak opravit chybu 404 ve WordPressu"},"content":{"rendered":"

Fungov\u00e1n\u00ed WordPressu je v\u011b\u0161tinou bezprobl\u00e9mov\u00e9, v\u0161ak, vyskytnou se probl\u00e9my, jen\u017e v\u00e1m mohou znep\u0159\u00edjemnit \u017eivot. A p\u0159esn\u011b takov\u00e1 je chyba 404.<\/p>\n

Pokud se pohybujete p\u0159edev\u0161\u00edm v administraci WordPressu, m\u016f\u017ee se st\u00e1t, \u017ee si probl\u00e9mu nev\u0161imnete. Proto je lep\u0161\u00ed, preventivn\u011b nainstalovat plugin, jen\u017e bude 404 dotazy logovat a vy tak budete m\u00edt mo\u017enost rychle zareagovat. Alternativou je aktivace Google Search Console, kter\u00e1 je zdarma a krom\u011b toho, \u017ee do n\u00ed m\u016f\u017eete vlo\u017eit sitemap soubor, upozorn\u00ed v\u00e1s na zv\u00fd\u0161en\u00fd v\u00fdskyt chyb 404.<\/p>\n

Podstr\u00e1nky webu zobrazuj\u00ed chybu 404<\/h2>\n

Pom\u011brn\u011b b\u011b\u017en\u00fd probl\u00e9m, kdy se v\u00e1m na\u010d\u00edt\u00e1 hlavn\u00ed strana webu, ale nem\u016f\u017eete se dostat na podstr\u00e1nky.<\/p>\n

Po\u0161kozen\u00fd htaccess soubor<\/h3>\n

St\u00e1v\u00e1 se to ob\u010das a doch\u00e1z\u00ed k tomu, pokud zap\u00ed\u0161ete do souboru nekorektn\u00ed pravidlo, nebo to mohou zp\u016fsobit odinstalovan\u00e9 pluginy, jen\u017e vlo\u017eily n\u011bjak\u00fd z\u00e1pis do souboru a ten bez pluginu nefunguje.<\/p>\n

\u0158e\u0161en\u00edm je opravit soubor. Zde je v\u00fdchoz\u00ed z\u00e1pis v souboru htaccess pro WordPress:<\/p>\n

# BEGIN WordPress<\/code><\/div>\n
<IfModule mod_rewrite.c><\/code><\/div>\n
RewriteEngine On<\/code><\/div>\n
RewriteBase \/<\/code><\/div>\n
RewriteRule ^index\\.php$ - [L]<\/code><\/div>\n
RewriteCond %{REQUEST_FILENAME} !-f<\/code><\/div>\n
RewriteCond %{REQUEST_FILENAME} !-d<\/code><\/div>\n
RewriteRule . \/index.php [L]<\/code><\/div>\n
<\/IfModule><\/code><\/div>\n
# <\/code>END<\/code> WordPress<\/code><\/div>\n

Na serveru nen\u00ed zapnut\u00fd rewrite mode<\/h3>\n

Toto se nest\u00e1v\u00e1 tak \u010dasto, ale ji\u017e jsem na to n\u011bkolikr\u00e1t narazil. Aby Apache byl schopen zpracovat takzvan\u00e9 „p\u011bkn\u00e9“ url, mus\u00ed m\u00edt aktivn\u00ed mod rewrite. Zjist\u00edte z php ini a pak po\u017e\u00e1d\u00e1te va\u0161eho spr\u00e1vce serveru o aktivaci.<\/p>\n

Znovu obnoven\u00ed rewrite rules pro „p\u011bkn\u00e9“ url<\/h3>\n

WordPress si ukl\u00e1d\u00e1 pravidla pro vytv\u00e1\u0159en\u00ed url a v p\u0159\u00edpad\u011b, \u017ee nainstalujete\/odinstalujete plugin a najednou v\u00e1m nefunguj\u00ed podstr\u00e1nky, sta\u010d\u00ed znovu vygenerovat tato pravidla.<\/p>\n

\"\"<\/a><\/p>\n

Jd\u011bte v adminsitraci do Nastaven\u00ed > Trval\u00e9 odkazy a tam jenklikn\u011bte na tla\u010d\u00edtko – Ulo\u017eit. WordPress si znovu projde v\u0161echny rewrite rules a ulo\u017e\u00ed si je.<\/p>\n

Nekorektn\u00ed definice custom post type<\/h3>\n

Tento probl\u00e9m je trochu o\u0161emetn\u011bj\u0161\u00ed a vy\u017eaduje trochu v\u011bt\u0161\u00ed p\u0159ehled o tom, co m\u00e1te ve WordPressu definov\u00e1no.<\/p>\n

Jeden z nejzn\u00e1m\u011bj\u0161\u00edch custom post typ\u016f je product z WooCommerce. Je definov\u00e1n pluginem a pokud by do\u0161lo k n\u011bjak\u00e9mu probl\u00e9mu, budou v\u00e1m fungovat str\u00e1nky, \u010dl\u00e1nky, ale ne produkty. D\u00edky tomu jste pom\u011brn\u011b rychle schopni detekovat probl\u00e9m. Kdy\u017e nainstalujete plugin, jen\u017e custom post type vytv\u00e1\u0159\u00ed, budete jej bu\u010f muset opravit, nebo deaktivovat.<\/p>\n

Probl\u00e9m nastav\u00e1 nap\u0159\u00edklad, pokud m\u00e1te na webu n\u011bjakou str\u00e1nku, kter\u00e1 se jmenuje stejn\u011b jako custom post type, nebo m\u00e1 va\u0161e definice n\u00e1zev stejn\u00fd, jako jeden z chr\u00e1n\u011bn\u00fdch jmen. Jejich seznam najdete v dokumentaci https:\/\/codex.wordpress.org\/Reserved_Terms.<\/p>\n

Neexistence c\u00edlov\u00e9 str\u00e1nky a chyba 404<\/h2>\n

Tento probl\u00e9m vznik\u00e1, pokud str\u00e1nku p\u0159ejmenujete, odstran\u00edte, nebo jste obsah migrovali z jin\u00e9ho syst\u00e9mu na WordPress. C\u00edlov\u00e1 url pak neexistuje a WordPress v\u00e1m spr\u00e1vn\u011b zobraz\u00ed str\u00e1nku s 404 chybou. \u0158e\u0161en\u00edm v tomto p\u0159\u00edpad\u011b je 301 p\u0159esm\u011brov\u00e1n\u00ed. O tom, co je 301 p\u0159esm\u011brov\u00e1n\u00ed psal ji\u017e p\u0159ed drahnou dobou Pavel Ungr – https:\/\/blog.bloxxter.cz\/trvale-presmerovani-301\/<\/a> – \u010dl\u00e1nek st\u00e1le plat\u00ed.<\/p>\n

Vy m\u00e1te ve WordPressu mo\u017enost p\u0159idat pravidlo pro redirect do htaccess, nebo pou\u017e\u00edt n\u011bkter\u00fd z plugin\u016f. J\u00e1 pou\u017e\u00edv\u00e1m Redirection<\/a>, proto\u017ee um\u00ed oboje – loguje 404 chyby a je v n\u011bm mo\u017en\u00e9 vytv\u00e1\u0159et 301 pravidla a to v\u010detn\u011b regul\u00e1rn\u00edch v\u00fdraz\u016f.<\/p>\n

WordPress v\u0161ak obsahuje jednu zaj\u00edmavou funkci a tou je, \u017ee si ukl\u00e1d\u00e1 posledn\u00ed zm\u011bnu url do custom fieldu, tak\u017ee pokud ud\u011bl\u00e1te zm\u011bnu url \u010dl\u00e1nku\/str\u00e1nky, m\u011bl by u star\u0161\u00edho tvaru odkazu prov\u00e9st 301 p\u0159esm\u011brov\u00e1n\u00ed. Nedr\u017e\u00ed ale celou historii, pouze posledn\u00ed zm\u011bnu.<\/p>\n

Rychl\u00e1 detekce probl\u00e9mu<\/h2>\n

Pokud nastane probl\u00e9m s 404 chybou, doporu\u010duji v Nastaven\u00ed > Trval\u00e9 odkazy, zm\u011bnit nastaven\u00ed na Z\u00e1kladn\u00ed a pokud se v\u00e1m v tu chv\u00edli za\u010dnou podstr\u00e1nky zobrazovat, hledejte probl\u00e9m v htaccessu, p\u0159eulo\u017ete trval\u00e9 odkazy, nebo zkontrolujte nastaven\u00ed php – mod rewrite.<\/p>\n

M\u00e1te probl\u00e9my s va\u0161\u00edm WordPress webem? Kontaktuje n\u00e1s na Toret.cz<\/a> a my v\u00e1m pom\u016f\u017eeme.<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"

Fungov\u00e1n\u00ed WordPressu je v\u011b\u0161tinou bezprobl\u00e9mov\u00e9, v\u0161ak, vyskytnou se probl\u00e9my, jen\u017e v\u00e1m mohou znep\u0159\u00edjemnit \u017eivot. A p\u0159esn\u011b takov\u00e1 je chyba 404. Pokud se pohybujete p\u0159edev\u0161\u00edm v administraci WordPressu, m\u016f\u017ee se st\u00e1t, \u017ee si probl\u00e9mu nev\u0161imnete. Proto je lep\u0161\u00ed, preventivn\u011b nainstalovat plugin, jen\u017e bude 404 dotazy logovat a vy tak budete m\u00edt mo\u017enost rychle zareagovat. Alternativou je<\/p>\n","protected":false},"author":1,"featured_media":5094,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[53,30,35],"tags":[],"class_list":["post-5093","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-reseni-problemu","category-wordpress","category-wordpress-zacatecnici"],"_links":{"self":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts\/5093"}],"collection":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/comments?post=5093"}],"version-history":[{"count":0,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts\/5093\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/media\/5094"}],"wp:attachment":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/media?parent=5093"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/categories?post=5093"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/tags?post=5093"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}