{"id":7684,"date":"2017-07-26T06:00:05","date_gmt":"2017-07-26T10:00:05","guid":{"rendered":"https:\/\/blog.litespeedtech.com\/?p=7684"},"modified":"2017-07-26T06:00:05","modified_gmt":"2017-07-26T10:00:05","slug":"wpw-rewrite-rules-in-the-proper-order","status":"publish","type":"post","link":"https:\/\/lswp.store\/index.php\/2017\/07\/26\/wpw-rewrite-rules-in-the-proper-order\/","title":{"rendered":"WpW: .htaccess and Rewrite Rules"},"content":{"rendered":"<p><img fetchpriority=\"high\" decoding=\"async\" class=\"size-full wp-image-7750\" src=\"https:\/\/lswp.store\/wp-content\/uploads\/2017\/07\/wpw11.jpg\" alt=\"\" width=\"640\" height=\"320\" srcset=\"https:\/\/lswp.store\/wp-content\/uploads\/2017\/07\/wpw11.jpg 640w, https:\/\/lswp.store\/wp-content\/uploads\/2017\/07\/wpw11-300x150.jpg 300w, https:\/\/lswp.store\/wp-content\/uploads\/2017\/07\/wpw11-600x300.jpg 600w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/p>\n<p>Welcome to another installment of <a href=\"http:\/\/blog.litespeedtech.com\/tag\/wordpress-wednesday\">WordPress Wednesday<\/a>!<\/p>\n<p>We\u2019ve covered a lot of complex topics here lately, so how about we give you a nice quick tip for a change? Today, we\u2019ve got a little tidbit related to your <code>.htaccess<\/code> file and LiteSpeed Cache Rewrite Rules.<\/p>\n<h2>What is <code>.htaccess<\/code>?<\/h2>\n<p>LiteSpeed Web Server supports the Apache <code>.htaccess<\/code> file. This configuration file is important because it allows us to enable or disable additional functionality, and to define URL redirect rules, among other things.<\/p>\n<p>When you look at the <code>.htaccess<\/code> in your WordPress root directory, there are two things you should notice:<\/p>\n<ol>\n<li>There should be a line that reads <code>CacheLookup on<\/code><\/li>\n<li>WordPress\u2019 URL rewrite rules (if there are any) should come <i>after<\/i> LiteSpeed\u2019s Cache rules.<\/li>\n<\/ol>\n<p>Under normal circumstances, this is not something you should have to worry about. There should not be any need for you to edit this file yourself. LiteSpeed&#8217;s WP plugin maintains the\u00a0<code>.htaccess<\/code>\u00a0file automatically. When the plugin is installed or uninstalled, enabled or disabled, or when you change relevant settings in your WP dashboard, <code>.htaccess<\/code> is updated to reflect that change.<\/p>\n<h2>In some more detail<\/h2>\n<p>If you have chosen to use pretty permalinks (i.e. your WordPress URLs look more like <code>example.com\/post-title<\/code> or <code>example.com\/2017\/07\/post-title<\/code> than <code>example.com\/?p=123<\/code>), then WP has used the <code>.htaccess<\/code> file in its root directory to define some rewrite rules. Depending on how many plugins you\u2019ve got installed and a variety of other factors, your <code>.htaccess<\/code> could be fairly simple like the one below, or it could be really hairy with many different blocks belonging to a variety of plugins and other software.<\/p>\n<h3>WordPress Rewrite Rules<\/h3>\n<p>This is an example of the lines that a basic WP installation would insert into <code>.htaccess<\/code>:<\/p>\n<pre># BEGIN WordPress\n&lt;IfModule mod_rewrite.c&gt;\nRewriteEngine On\nRewriteBase \/\nRewriteRule ^index\\.php$ - [L]\nRewriteCond %{REQUEST_FILENAME} !-f\nRewriteCond %{REQUEST_FILENAME} !-d\nRewriteRule . \/index.php [L]\n&lt;\/IfModule&gt;\n# END WordPress\n<\/pre>\n<h3>LiteSpeed Cache Rewrite Rules<\/h3>\n<p>LiteSpeed Cache, too, uses <code>.htaccess<\/code>. Here\u2019s an example of the LSCache-related lines you might find in your <code>.htaccess<\/code>:<\/p>\n<pre># BEGIN LSCACHE\n## LITESPEED WP CACHE PLUGIN - Do not edit the contents of this block! ##\n\nRewriteEngine on\nCacheLookup on\nRewriteRule .* - [E=Cache-Control:no-autoflush]\nRewriteRule \\.litespeed_conf\\.dat - [F,L]\n\n### marker CACHE RESOURCE start ###\nRewriteRule wp-content\/.*\/[^\/]*(responsive|css|js|dynamic|loader|fonts)\\.php - [E=cache-control:max-age=3600]\n### marker CACHE RESOURCE end ###\n\n### marker FAVICON start ###\nRewriteRule favicon\\.ico$ - [E=cache-control:max-age=86400]\n### marker FAVICON end ###\n\n### marker WEBP start ###\nRewriteCond %{HTTP_ACCEPT} \"image\/webp\" [or]\nRewriteCond %{HTTP_USER_AGENT} \"Page Speed\"\nRewriteRule .* - [E=Cache-Control:vary=%{ENV:LSCACHE_VARY_VALUE}+webp]\nRewriteCond %{HTTP_USER_AGENT} iPhone.*Version\/(\\d{2}).*Safari\nRewriteCond %1 &gt;13\nRewriteRule .* - [E=Cache-Control:vary=%{ENV:LSCACHE_VARY_VALUE}+webp]\n### marker WEBP end ###\n\n### marker DROPQS start ###\nCacheKeyModify -qs:fbclid\nCacheKeyModify -qs:gclid\nCacheKeyModify -qs:utm*\nCacheKeyModify -qs:_ga\n### marker DROPQS end ###\n\n\n## LITESPEED WP CACHE PLUGIN - Do not edit the contents of this block! ##\n# END LSCACHE\n<\/pre>\n<p>The exact lines you see for WordPress and LSCache depend on which options you have enabled in the plugin, and may not match these examples directly, but they should be pretty similar.<\/p>\n<h3>Putting Them Together<\/h3>\n<p>In order for LSCache to work properly, two things must be true:<\/p>\n<ol>\n<li>Public Cache Lookup must be enabled via the <code>CacheLookup on<\/code> directive.<\/li>\n<li>The <code>LITESPEED WP CACHE PLUGIN<\/code> block must appear before any WordPress rewrite rules.<\/li>\n<\/ol>\n<p>If you&#8217;re noticing quirky behavior, take a look at your configuration file. You can view it via\u00a0<strong>WP Dashboard &gt; LiteSpeed Cache &gt; Toolbox &gt; View .htaccess<\/strong>.\u00a0Like we mentioned earlier, LSCache for WordPress automatically handles cache-related changes to <code>.htaccess<\/code>, but if it has been manually updated or otherwise manipulated by another plugin, you may find irregularities that need to be corrected.<\/p>\n<p>&#8212;<\/p>\n<p>Have some of your own ideas for future <a href=\"http:\/\/blog.litespeedtech.com\/tag\/wordpress-wednesday\">WordPress Wednesday<\/a> topics? Leave us a comment!<\/p>\n<p>Don\u2019t forget to meet us back here next week for the next installment. In the meantime, here are a few other things you can do:<\/p>\n<ul>\n<li>Subscribe to the <a href=\"http:\/\/blog.litespeedtech.com\/tag\/wordpress-wednesday\/feed\/\">WordPress Wednesday RSS feed<\/a><\/li>\n<li>Download <a href=\"https:\/\/wordpress.org\/plugins\/litespeed-cache\/\">LiteSpeed Cache for WordPress plugin<\/a><\/li>\n<li>Learn more about the plugin <a href=\"https:\/\/www.litespeedtech.com\/products\/cache-plugins\/wordpress-acceleration\">on our website<\/a><\/li>\n<\/ul>\n<p>&#8212;<br \/>\n<em>This content was last verified and updated in October of 2022. If you find an inaccuracy, please let us know! In the meantime, see <a href=\"https:\/\/docs.litespeedtech.com\">our documentation site<\/a>\u00a0for the most up-to-date information.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here&#8217;s a little bit about .htaccess, rewrite rules, and how they relate to LSCWP.<\/p>\n","protected":false},"author":1,"featured_media":8160,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[28],"tags":[253,316,317],"class_list":["post-7684","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cache","tag-rewrite-rules","tag-wordpress","tag-wordpress-wednesday"],"jetpack_featured_media_url":"https:\/\/lswp.store\/wp-content\/uploads\/2017\/07\/wpw11-1.jpg","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/posts\/7684","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/comments?post=7684"}],"version-history":[{"count":0,"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/posts\/7684\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/media\/8160"}],"wp:attachment":[{"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/media?parent=7684"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/categories?post=7684"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/tags?post=7684"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}