.htaccess - PHP auto_prepend_file in CGI-MODE without modifying php.ini -


i need auto_prepend_file on requests folder using .htaccess. problem is, php runs under cgi-mode, , cant modify other php file or php.ini. tat's why i'm not using php_value auto_prepend_file "/testing.php" on .htaccess file.

is there way of doing under specifications?

assuming mod_rewrite enabled on server, can following.

in .htaccess add following:

rewriteengine on rewritecond %{request_uri} !/testing\.php rewriterule ^(.*)$ /testing.php?url=$1 [l] 

in testing.php, whatever want do. @ end of file, this:

$file = $_get['url']; if( file_points_to_sensible_location( $file ) && file_exists( $file ) ) {   require( $file ); } 

file_exist existing function. file_points_to_sensible_location(...) have write. if mess up, might able execute or dump files don't want expose.


edit: can prevent happening requests adding additional conditions .htaccess file. example: rewritecond %{request_uri} !\.(jpg|jpeg|png|gif|css|js|unicorn)$ prevent testing.php being executed on files ending extension. condition rewritecond %{request_uri} \.php$ let work on requests ending .php.

to make work wordpress, instead of require( $file ) can use require( "index.php" ). since url same, wordpress still work.

to make work other rewriterules, you'll need move rewritelogic testing.php. change $file contain whatever should contain after rewrite , include/require that. remove corresponding rules .htaccess.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -