Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I make a dynamic .htaccess file?

Can I make my .htaccess be generated with php?
I would like to use php to dynamicly create my htaccess file from information from the database.
It would save me the trouble of making a new .htaccess file whenever I change a bit of my code.

like image 885
InsanityNet Avatar asked Oct 13 '25 12:10

InsanityNet


1 Answers

You can read and write files with the file system functions, for example:

$data = <<<EOF
RewriteEngine on
RewriteRule …
EOF;
file_put_contents('.htaccess', $data);

But it would be more flexible if you use one static rule that redirect the requests to your PHP file that then does the rest.

like image 96
Gumbo Avatar answered Oct 15 '25 04:10

Gumbo