I have following situation:
web is divided into sections
www.example.com/sectionA
www.example.com/sectionB
www.example.com/sectionC
etc
www.example.com/sectionA/document is redirected to www.example.com/index.php (with REQUEST['URI'] applied in php in order to get the name of the document and section)
now I also have
www.example.com/sectionA/fileA.php The fileA.php is located physically in web's root
but also have
www.example.com/sectionD/fileB.php The fileB.php is located physically in the physical directory sectionD
Now I'd like to:
from given url www.example.com/sectionA/fileA.php check if fileA.php exists in directory sectionA and call it
if not, check if fileA.php exists in root and call /fileA.php?section=sectionA
if not, call index.php
Is it possible? I am not able to read single filename from REQUEST. I was trying all possible and impossible with no success.
[EDIT] I have worked following code which seems to work, but... there might be a much better workaround.
- Code: Select all
RewriteRule ^([^/!\.]+)/+([^/]+\.php)?$ - [E=file:$2,E=dir:$1]
RewriteCond %{DOCUMENT_ROOT}/%{ENV:dir}/%{ENV:file} !-f
RewriteCond /%{ENV:file} !-f
RewriteRule ^([^/!\.]+)/+([^/]+\.php)?$ $2 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
PS: Options +FollowSymLinks causes internal error 500.
Any help appreciated!