I want to display contents as (not existing) sub-folders. All those sub-folder strings should be sent to file.php and attached as variable: “n”.
My PHP script is already working fine. (If I attach the variables in the address bar file.php displays everything it should display.) But I seem to have at least one error in my .htaccess definitions which I can’t find for days now. (All the pages are accessible still, but for some reason I can’t reach file.php if I type any string (with allowed chars only) as sub-folder. (All real files are meant to stay accessible because they are real documents or sub-folders, which should be excluded from the rewrite rule through conditions in my .htaccess file.)
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z0-9_-]+)/?$ file.php?n=$1 [QSA,NC,L]
Can anyone give me a hint why my definitions don’t do what I want them to do?
For the first level, this is working just fine. So if ‘foo/’ isn’t working for you, I think your .htaccess file isn’t being parsed properly.
If its ‘lower levels’ not working (‘foo/bar/’ and such) that is your problem, use this rewriterule instead:
It will match any level of nesting and give you the whole path.
(For just the last subdirectory, use $2 or $3 instead of $1.)