I have a PHP web app located on shared hosting. My goal is to modify .htaccess file from PHP code when the PHP page is running. I need that .htaccess to insert a couple of mod_rewrite lines into it.
The problem is that on Windows+Apache I can dynamically modify .htaccess file but the same code on Linux reports a problem when I try to access this file in any way (copy or fopen):
'failed to open stream: Permission denied'
I have given .htaccess file 777 permissions – still no result. WHat prevents me from doing this? How can I develop a workaround?
P.S. My initial goal was to be able to add a new RewriteRule into .htaccess that maps a newly added category_id with new category_name.
If it wasn’t shared hosting, I would use something like RewriteMap (in main Apache config) and would be able to access the map file.
This is the first real limitation I’ve been unable to tackle with PHP+Apache, but I hope it’s circuventable too.
I want to suggest something else that also works. Instead of writing a rule for every ‘special’ url, why not use one for all?
I found it a whole lot easier to use what wordpress uses: every url is redirected to the index.
All you have to do is, set up the index file, read in the directory that was loaded (perhaps using $_SERVER[‘URI_REQUEST’]), and deal with it.
add to .htaccess this:
Thanks to that chunck you have a system somewhat unlimited at your disposal. If you ever feel like renaming you categrory url, or add another special case, it’s already ready!