RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/cache/$1-$2.html -f
RewriteRule ^(.*) /cache/$1-$2.html
RewriteRule !((.txt)|(.xml)|(.json)|(.html)|(.js)|(.mp4)|images|uploads\/(.*)|cache\/(.*)|resources\/(.*)|control\/(.*)|fonts\/(.*)|offline\/(.*)|stylesheets\/(.*)|libs\/(.*)|javascripts\/(.*))$ index.php [NC]
This is my htaccess file. It should be serving my cache files of /cache folder.
The problem I'm facing is: I have a url like site.com.br/blog/example-post/ But I am saving this cache as blog-example-post.html
Also, if no cache file found, then open index.php to control all requests. But, using cache I will decrease my server and DB requests.
Can someone please help me to replace all / from requests to - in htaccess?
Edit: a possible solution for site.com.br/blog/my-post/amp/ (saved as: blog-my-post-amp.html
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/cache/$1-$2.html -f
RewriteRule ^([^/]+)/([^/]+)/$ /cache/$1-$2.html [NC,L]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/$ /cache/$1-$2-$3.html [L]
Update: How it is working to me now
RewriteCond %{DOCUMENT_ROOT}/cache/$1.html -f
RewriteRule ^([^/]+)/$ /cache/$1.html [L]
RewriteCond %{DOCUMENT_ROOT}/cache/$1-$2.html -f
RewriteRule ^([^/]+)/([^/]+)/$ /cache/$1-$2.html [L]
RewriteCond %{DOCUMENT_ROOT}/cache/$1-$2-$3.html -f
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/$ /cache/$1-$2-$3.html [L]
RewriteCond %{DOCUMENT_ROOT}/cache/$1-$2-$3-$4.html -f
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/$ /cache/$1-$2-$3-$4.html [L]
RewriteCond %{DOCUMENT_ROOT}/cache/$1.xml -f
RewriteRule ^([^/]+)/$ /cache/$1.xml [L]
RewriteCond %{DOCUMENT_ROOT}/cache/$1-$2.xml -f
RewriteRule ^([^/]+)/([^/]+)/$ /cache/$1-$2.xml [L]
RewriteCond %{DOCUMENT_ROOT}/cache/$1-$2-$3.xml -f
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/$ /cache/$1-$2-$3.xml [L]
RewriteCond %{DOCUMENT_ROOT}/cache/$1-$2-$3-$4.xml -f
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/$ /cache/$1-$2-$3-$4.xml [L]
I must fix somethings and maybe optimze the code. I will update here when it reach 100%