Site icon Knowledge Base| Kiến thức Dịch vụ P.A Việt Nam

Khắc phục lỗi 404 khi sử dụng plugin WP Super Cache

WP Super Cache là một trong những plugin tạo cache tốt nhất hiện nay, đó là điều không cần phải bàn cãi. Tuy nhiên, ngoài những ưu điểm như cài đặt và thiết lập đơn giản, có nhiều tùy chọn bổ sung, hỗ trợ CDN… WP Super Cache cũng sở hữu một điểm yếu chết người đó là dễ gây ra lỗi 404, đặc biệt là khi sử dụng phương thức mod_rewrite caching.

Sở dĩ mod_rewrite caching dễ gây ra lỗi 404 bởi vì phương thức này yêu cầu phải chỉnh sửa tập tin .htaccess của thư mục gốc (nơi cài đặt WordPress). Nếu bạn tiến hành xóa bỏ plugin hoặc chuyển sang phương thức tạo cache khác, những thiết lập của WP Super Cache trong .htaccess sẽ không bị xóa, dẫn đến gây ra lỗi 404.

Để làm được điều đó, trước tiên các bạn cần phải xóa toàn bộ nội dung của file .htaccess nằm trong thư mục gốc. Sau đó thay thế bằng nội dung sau :

# BEGIN WordPress – WP Super Cache
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{QUERY_STRING} !.*=.*
RewriteCond %{HTTP_COOKIE} !^.*(comment_author_|wordpress|wp-postpass_).*$
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{HTTP_USER_AGENT} !^.*(2.0\ MMP|240×320|400X240|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo|Elaine/3.0|EudoraWeb|Googlebot-Mobile|hiptop|IEMobile|KYOCERA/WX310K|LG/U990|MIDP-2.|MMEF20|MOT-V|NetFront|Newt|Nintendo\ Wii|Nitro|Nokia|Opera\ Mini|Palm|PlayStation\ Portable|portalmmm|Proxinet|ProxiNet|SHARP-TQ-GX10|SHG-i900|Small|SonyEricsson|Symbian\ OS|SymbianOS|TS21i-10|UP.Browser|UP.Link|webOS|Windows\ CE|WinWAP|YahooSeeker/M1A1-R2D2|iPhone|iPod|Android|BlackBerry9530|LG-TU915\ Obigo|LGE\ VX|webOS|Nokia5800).*
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html.gz -f
RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html.gz [L]

RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{QUERY_STRING} !.*=.*
RewriteCond %{QUERY_STRING} !.*attachment_id=.*
RewriteCond %{HTTP_COOKIE} !^.*(comment_author_|wordpress|wp-postpass_).*$
RewriteCond %{HTTP_USER_AGENT} !^.*(2.0\ MMP|240×320|400X240|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo|Elaine/3.0|EudoraWeb|Googlebot-Mobile|hiptop|IEMobile|KYOCERA/WX310K|LG/U990|MIDP-2.|MMEF20|MOT-V|NetFront|Newt|Nintendo\ Wii|Nitro|Nokia|Opera\ Mini|Palm|PlayStation\ Portable|portalmmm|Proxinet|ProxiNet|SHARP-TQ-GX10|SHG-i900|Small|SonyEricsson|Symbian\ OS|SymbianOS|TS21i-10|UP.Browser|UP.Link|webOS|Windows\ CE|WinWAP|YahooSeeker/M1A1-R2D2|iPhone|iPod|Android|BlackBerry9530|LG-TU915\ Obigo|LGE\ VX|webOS|Nokia5800).*
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html -f
RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# BEGIN WordPress – WP Super Cache

Rate this post
Exit mobile version