Here is my .htaccess:
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ([^/]+/.*) index.php?dir=%{REQUEST_URI}
The htaccess lives in test.com/main/.htaccess
I can access test.com/main/ and test.com/index.php fine
test.com/main/directory gets rewritten to test.com/main/index.php?dir=/main/directory/ BUT test.com/main/directory stays in the url bar. This is good.
The problem is when I try to access sub-sub directories. When I access test.com/main/foler1/folder2 it gets rewritten to index.php?dir=/main/folder1/folder2/. This is also good, however test.com/main/folder1/folder2/?dir=/main/folder1/folder2/ shows up in the address bar instead of keeping test.com/main/folder1/folder2 in the url bar. This is the problem.
I want all sub directories, not just the direct children of main to keep the directory in the url bar while rewriting. The direct children do this fine, but any directories under that rewrite in a way where my get variables show up.
The purpose of this rewrite is so I don’t have to copy in an index.php file into every newly created folder so copying the .htaccess into each folder defeats the purpose.
I’ll add the solution I found while testing mootinator’s solution.
Instead of linking to
test.com/main/foler1/folder2
link to
test.com/main/foler1/folder2/ (Include the slash!)
Redirection will successfully redirect to
index.php?dir=/main/folder1/folder2/
while
test.com/main/foler1/folder2/
stays in the url bar.
It’s a somewhat hackish solution but it should work just fine.