Title: Caddy Re-write Rule support
Last modified: November 13, 2020

---

# Caddy Re-write Rule support

 *  Resolved [silaslin](https://wordpress.org/support/users/silaslin/)
 * (@silaslin)
 * [5 years, 5 months ago](https://wordpress.org/support/topic/caddy-re-write-rule-support/)
 * Hi, I’ve change my web server from Nginx to Caddy.
    So I’ve to change my config.
   Since Caddy does not support environment variables, Could you help me to complete
   my code?
 * I don’t know how to pass the right parameter for mobile devices.
 *     ```
       try_files @mobile /wp-content/cache/wpp-cache/{host}{uri}/index.html {path} {path}/index.php?{query}{???ENV:WPP_MOBILE_EXT???}
       ```
   
 * This is my code:
 *     ```
       (wppcache) {
   
       	header Vary Accept-Encoding
   
       	@mobile {
       	  header_regexp User-Agent Mobile|Android|Kindle|BlackBerry|Opera\sMini|Opera\sMini
       	}	
   
       	@is-gzip {
       		file
       		path *.html_gz *.html_mobile_gz *.html_amp_gz *.html_mobile_amp_gz
       	}
   
       	header @is-gzip {
       	    Content-Type text/html
       	    Content-Encoding gzip
       	}
   
       	@no-gzip {
       		file
       		not path *.html_gz *.html_mobile_gz *.html_amp_gz *.html_mobile_amp_gz
       	}
   
       	@cache {
       		not header_regexp Cookie "wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in|wptouch_switch_toggle|comment_author_|comment_author_email_"
       		not path_regexp "(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(index)?.xml|[a-z0-9-]+-sitemap([0-9]+)?.xml)"
       		not method POST
       		not expression {query} != ''
           }
   
           route @cache {
               try_files /wp-content/cache/wpp-cache/{host}{uri}/index.html {path} {path}/index.php?{query}
           }
       }
   
       domain.com {
           # Change the path here according to your setup
       	root * /var/www/domain.com
       	file_server
   
          # Change the path here according to your server
           php_fastcgi unix//run/php/php7.4-fpm.sock
   
           import wppcache
       	encode @no-gzip zstd gzip    
       }
       ```
   
    -  This topic was modified 5 years, 5 months ago by [silaslin](https://wordpress.org/support/users/silaslin/).

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [silaslin](https://wordpress.org/support/users/silaslin/)
 * (@silaslin)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/caddy-re-write-rule-support/#post-13729299)
 * This is the last modified code
 *     ```
       (wppcache) {
   
       	header Vary Accept-Encoding
   
       	@is-gzip {
       		file
       		path *.html_gz *.html_mobile_gz *.html_amp_gz *.html_mobile_amp_gz
       	}
   
       	header @is-gzip {
       	    Content-Type text/html
       	    Content-Encoding gzip
       	}
   
       	@no-gzip {
       		file
       		not path *.html_gz *.html_mobile_gz *.html_amp_gz *.html_mobile_amp_gz
       	}
   
       	@mobile header_regexp User-Agent Mobile|Android|Kindle|BlackBerry|Opera\sMini|Opera\sMini
       	@amp path /amp/*
       	@gzip header_regexp Accept-Encoding gzip
       	@mobile-amp {
       		header_regexp User-Agent Mobile|Android|Kindle|BlackBerry|Opera\sMini|Opera\sMini
       		path /amp/*
       	}
       	@mobile-gzip {
       		header_regexp User-Agent Mobile|Android|Kindle|BlackBerry|Opera\sMini|Opera\sMini
       		header_regexp Accept-Encoding gzip
       	}
       	@amp-gzip {
       		path /amp/*
       		header_regexp Accept-Encoding gzip
       	}
       	@mobile-amp-gzip {
       		header_regexp User-Agent Mobile|Android|Kindle|BlackBerry|Opera\sMini|Opera\sMini
       		path /amp/*
       		header_regexp Accept-Encoding gzip
       	}	
       	@else {
       		not header_regexp User-Agent Mobile|Android|Kindle|BlackBerry|Opera\sMini|Opera\sMini
       		not path /amp/*
       		not header_regexp Accept-Encoding gzip
       	}
   
       	@cache {
       		not header_regexp Cookie "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in"
       		not path_regexp "(/wp-json/|/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(index)?.xml|[a-z0-9-]+-sitemap([0-9]+)?.xml)"
       		not method POST
       		not expression {query} != ''
           }
   
           route @cache {
       		handle @mobile {
       			try_files /wp-content/cache/wpp-cache/{host}{uri}/index.html {path} {path}/index.php?_mobile
       		}
       		handle @amp {
       			try_files /wp-content/cache/wpp-cache/{host}{uri}/index.html {path} {path}/index.php?_amp
       		}
       		handle @gzip {
       			try_files /wp-content/cache/wpp-cache/{host}{uri}/index.html {path} {path}/index.php?_gzip
       		}
       		handle @mobile-amp {
       			try_files /wp-content/cache/wpp-cache/{host}{uri}/index.html {path} {path}/index.php?_mobile_amp
       		}
       		handle @mobile-gzip {
       			try_files /wp-content/cache/wpp-cache/{host}{uri}/index.html {path} {path}/index.php?_mobile_gzip
       		}
       		handle @amp-gzip {
       			try_files /wp-content/cache/wpp-cache/{host}{uri}/index.html {path} {path}/index.php?_amp_gzip
       		}
       		handle @mobile-amp-gzip {
       			try_files /wp-content/cache/wpp-cache/{host}{uri}/index.html {path} {path}/index.php?_mobile_amp_gzip		
       		}
       		handle @else {
       			try_files /wp-content/cache/wpp-cache/{host}{uri}/index.html {path} {path}/index.php?{query}
       		}
           }
       }
   
       domain.com {
           # Change the path here according to your setup
       	root * /var/www/domain.com
       	file_server
   
          # Change the path here according to your server
           php_fastcgi unix//run/php/php7.4-fpm.sock
   
           import wppcache
           encode @no-gzip zstd gzip    
       }
       ```
   
 *  Thread Starter [silaslin](https://wordpress.org/support/users/silaslin/)
 * (@silaslin)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/caddy-re-write-rule-support/#post-13842544)
 * I’ve found some bugs and fixed.
 *     ```
       (wppcache) {
   
               header Vary Accept-Encoding
   
               @is-gzip {
                       file
                       path *.html_gz *.html_mobile_gz *.html_amp_gz *.html_mobile_amp_gz
               }
   
               header @is-gzip {
                   Content-Type text/html
                   Content-Encoding gzip
               }
   
               @no-gzip {
                       file
                       not path *.html_gz *.html_mobile_gz *.html_amp_gz *.html_mobile_amp_gz
               }
   
               @mobile header_regexp User-Agent Mobile|Android|Kindle|BlackBerry|Opera\sMini|Opera\sMini
               @amp path /amp/*
               @gzip header_regexp Accept-Encoding gzip        
               @mobile-gzip {
                       header_regexp User-Agent Mobile|Android|Kindle|BlackBerry|Opera\sMini|Opera\sMini
                       header_regexp Accept-Encoding gzip
               }
               @amp-gzip {
                       path /amp/*
                       header_regexp Accept-Encoding gzip
               }
               @mobile-amp-gzip {
                       header_regexp User-Agent Mobile|Android|Kindle|BlackBerry|Opera\sMini|Opera\sMini
                       path /amp/*
                       header_regexp Accept-Encoding gzip
               }       
               @else {
                       not header_regexp User-Agent Mobile|Android|Kindle|BlackBerry|Opera\sMini|Opera\sMini
                       not path /amp/*
                       not header_regexp Accept-Encoding gzip
               }
   
               @cache {
                       not header_regexp Cookie "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in"
                       not path_regexp "(/wp-json/|/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(index)?.xml|[a-z0-9-]+-sitemap([0-9]+)?.xml)"
                       not method POST
                       not expression {query} != ''
           }
   
           route @cache {
                       handle @mobile {
                               try_files /wp-content/cache/wpp-cache/{host}{uri}/index.html {path} {path}/index.php?_mobile
                       }
                       handle @amp {
                               try_files /wp-content/cache/wpp-cache/{host}{uri}/index.html {path} {path}/index.php?_amp
                       }
                       handle @gzip {
                               try_files /wp-content/cache/wpp-cache/{host}{uri}/index.html {path} {path}/index.php?_gz
                       }
                       handle @mobile-gzip {
                               try_files /wp-content/cache/wpp-cache/{host}{uri}/index.html {path} {path}/index.php?_mobile_gz
                       }
                       handle @amp-gzip {
                               try_files /wp-content/cache/wpp-cache/{host}{uri}/index.html {path} {path}/index.php?_amp_gz
                       }
                       handle @mobile-amp-gzip {
                               try_files /wp-content/cache/wpp-cache/{host}{uri}/index.html {path} {path}/index.php?_mobile_amp_gz          
                       }
                       handle @else {
                               try_files /wp-content/cache/wpp-cache/{host}{uri}/index.html {path} {path}/index.php?{query}
                       }
           }
       }
   
       domain.com {
           # Change the path here according to your setup
       	root * /var/www/domain.com
       	file_server
   
          # Change the path here according to your server
           php_fastcgi unix//run/php/php7.4-fpm.sock
   
           import wppcache
           encode @no-gzip zstd gzip    
       }
       ```
   
    -  This reply was modified 5 years, 3 months ago by [silaslin](https://wordpress.org/support/users/silaslin/).

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Caddy Re-write Rule support’ is closed to new replies.

 * ![](https://ps.w.org/wp-performance/assets/icon-128x128.png?rev=2002746)
 * [WP Performance](https://wordpress.org/plugins/wp-performance/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-performance/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-performance/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-performance/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-performance/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-performance/reviews/)

 * 2 replies
 * 1 participant
 * Last reply from: [silaslin](https://wordpress.org/support/users/silaslin/)
 * Last activity: [5 years, 3 months ago](https://wordpress.org/support/topic/caddy-re-write-rule-support/#post-13842544)
 * Status: resolved