Mansoor
Mansoor

Reputation: 285

Mod_rewrite: How to see the variables content?

Is there way to display the content of mod_rewrite variables like THE_REQUEST or REQUEST_FILENAME using javascript or PHP?

Upvotes: 0

Views: 677

Answers (1)

esquireofoz
esquireofoz

Reputation: 48

Yes, this can be done in PHP using the $_SERVER variable if the mod_rewrite variables have been exported into the Apache environment variables.

In order to export the Apache mod_rewrite variables so it is accessible by PHP via the Apache environmental variables, ensure the Apache VirtualHost contains the configuration below:

RewriteEngine On
RewriteRule .* - [E=API_VERSION:%{API_VERSION},NE]
RewriteRule .* - [E=THE_REQUEST:%{THE_REQUEST},NE]
RewriteRule .* - [E=REQUEST_URI:%{REQUEST_URI},NE]
RewriteRule .* - [E=REQUEST_FILENAME:%{REQUEST_FILENAME},NE]
RewriteRule .* - [E=IS_SUBREQ:%{IS_SUBREQ},NE]
RewriteRule .* - [E=HTTPS:%{HTTPS},NE]

Once these variables have been exported, PHP can be used to render the mod_rewrite THE_REQUEST and REQUEST_FILENAME variables, or any other Apache environment variables.

<?php
echo $_SERVER['THE_REQUEST'];
echo $_SERVER['REQUEST_FILENAME'];
?>

Upvotes: 2

Related Questions