Apache Expression Functions and .htaccess

Soldato
Joined
3 Jun 2005
Posts
3,239
Location
The South
Hi All,

Essentially i'm wanting to Base64 encode the requested file/url and redirect to a script with it as a query string, eg -
Code:
http://localhost/awesome.html --> http://localhost/index.php?q=YXdlc29tZS5odG1s


From reading the documentation (https://httpd.apache.org/docs/2.4/expr.html) this should technically be doable using Apache's Base64 expression function and the usual RewriteRules within htaccess, like so -
Code:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !index\.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?q=%{base64:$1} [L,QSA]


But i'm getting absolutely no where with expression functions (have tried others like MD5/SHA1 etc) and getting them to run/output anything; expression variables (eg - ${REQUEST_FILENAME}) do work however.

Has anyone had much luck with expression functions within the .htaccess? And/or know where i'm going wrong with the above?

I appreciate this could be handled on the scripts' frontend but at the moment there's a fair few hurdles preventing me doing this hence trying to get the "easier" (oxymoron and a half) option to work.

edit - Just to add, this is using Apache 2.4.41 (supports expressions).
 
Back
Top Bottom