I have page requests to my site that look like and are served as:
/directory/this_is_page_name/
I'm trying to setup my /.htaccess file to serve the request with the following files on the backend:
If found (and if the browser can support it), one of the following:
/cache/this_is_page_name.html.gz
/cache/this_is_page_name.html
Else, serve the following file:
/directory.php?name=this_is_page_name
This directory.php file serves the same content but won't be as fast. However, it will generate the .html.gz and .html files for future requests and save them in the cache.
This is what my .htaccess file looks like so far:
RewriteEngine On
RewriteBase /
<Files .html.gz>
ForceType text/html
</Files>
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{REQUEST_FILENAME}.gz -f
RewriteRule ^(.*)$ $1.gz [L]
RewriteRule ^directory/(.+)/$ /$1.html [QSA,L]
ErrorDocument 404 /directory.php?name=$1
There is a big error on the 404 line in that the $1 doesn't pass anything, but also any 404 error would get passed to that document, which would not be correct. I don't even think a 404 error line would be proper.
How could I make this script work better?
Thanks