Reading rewritten (mod_rewrite) files from php
Assuming you only have a file url (hosted on the same server as the app) that was rewritten using mod_rewrite rules.
How would you read the contents of this file from PHP without directly accessing the .htaccess file or the rewrite rules used to generate the original URL?
I am trying to extract all script tags that have a "src" attribute, get the content of the target file, merge all of them into one big javascript file, minify it, then use it to do that.
The problem is that reading all files with file_get_contents seems to slow down the page, so I was looking at alternatives and if I could somehow read files directly from the filesystem without making other requests in the background, but for that I will need to find the path to the files and some will be accessible via the urls that have been rewritten.
a source to share
You cannot enable it as if it were the original PHP, only get the PHP results by itself.
If you have fopen wrappers, it's as easy as using require , include, or file_get_contents on the rewritten url. Otherwise, you fsockopen and curl as parameters to create an HTTP request for the result.
a source to share
PHP lies behind apache and has file system access using fopen-like or include-like etc ... The Rewrite module will not work for this access as these functions use OS file access routines but not apache ...
There is no way to do this, but implement the same url rewriting rules in the php-script as in .htaccess, because apache-rewriting and php file access know nothing about each other and are on completely different layers of the web applications.
AFTER CHANGE: The only way is to move your rewrite rules to php script and use php filesystem access after parsing urls through php (don't rewrite module).
a source to share