Variables in the .htaccess file

Is there a way to store and retrieve variables in the entire htaccess file. The entire search that I just show shows how to create a variable with RegEx via mod_rewrite to apply it to the query string. This is not what I'm trying to do. I am implementing a version control system for a project with several applications. Current versions of the project are stored in the folder structure, for example: product/applications/application/version In the applications folder and several versions in each application folder there will be several applications, such as: v1.0 , v1.1 , v2.0 , etc. .

One of the things I'm trying to accomplish is to use htaccess for version control (I already use it to rewrite application URLs, I just want the version number in the example below 0.1 be the given variable at the top of my htaccess file. is it?

 RewriteEngine On Options +FollowSymlinks # version here is 0.1 and I would want it # defined as $apiVersion if possible # it is the same for both of these rewrites. RewriteRule ^api/json$ /malvern/api/api/v0.1/public/api.php?format=json [NC,L] RewriteRule ^api/xml$ /malvern/api/api/v0.1/public/api.php?format=xml [NC,L] # version here is also 0.1 but would be # a differnt variable than the first RewriteRule ^srsmith/rate$ /malvern/webship/webship/v0.1/apps/ratepackage/public/index.php [NC,QSA,L] 
+4
source share
1 answer

Try using the E flag in mod_rewrite. At the very top of your rules add:

 RewriteRule .* - [E=VERSION:v1.0] 

or no matter which version you want, then whenever you want to use your version, do the following:

 RewriteRule ^api/json$ /malvern/api/api/%{ENV:VERSION}/public/api.php?format=json [NC,L] RewriteRule ^api/xml$ /malvern/api/api/%{ENV:VERSION}/public/api.php?format=xml [NC,L] 
+7
source

Source: https://habr.com/ru/post/1389815/


All Articles