Tutorial :Accessing $_SERVER['DOCUMENT_ROOT'] value in .htaccess file



Question:

I need the path specified in $_SERVER['DOCUMENT_ROOT'] to be accessible in .htaccess file. Is there a way to access it there?

I basically need to point to a file kept at the root and need the actual file system path and not the URL path. So instead of using a hard coded value, I'd like to be able to use a variable.

Thanks.


Solution:1

$_SERVER is a PHP variable, whereas .htaccess files use Apache's configuration language. Sadly, there is no way to reach into PHP from Apache's config files.

The solution I've seen in many projects is to have an installation script write a customized .htaccess file out when the application is installed. Not quite ideal and a bit more work, but it gets the job done.


Solution:2

I believe %{DOCUMENT_ROOT} is only available in RewriteCond


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »