I have a website that already has several subdirectories. (All existing in the server file system) I want to create new “virtual” subdirs with htaccess, but I want the htaccess rule to work for the directories listed in the database and not be in the file system.
i.e. The file system has: / dir1 / and / dir2 /
There is an entry in the MySQL database for 'dir3' and 'dir4'
I want too:
A: mysite.com/dir1/and mysite.com/dir2/display existing old content
B: mysite.com/dir3/ and mysite.com/dir4/ display the contents from MySQL provided by PHP sctipt via redirection, for example: mysite.com/myscript.php?dir=dir3
C: mysite.com/dir5/ 404 display error (Dir does not exist in the database and database)
Basically I want .htaccess to work as follows: IF DIR exists in the database - apply the rewrite rule and show the content from myscript.php? Dir = dir
ELSE does not apply any rules.
I can create a separate php script that can return 0/1 if the given dir name exists in the database or not, but how to get mod_rewrite to get data from this script?
Is this possible with htaccess / PHP?
source
share