I know there are thousands of thousands questions like this asked, but I can't seem to find an appropriate solution for my problem.
I'm trying to write a download script. The folder structure is like this:
- __admin/
- __uploads/
- index.php
- .htaccess
This is my .htaccess file:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/index.php
RewriteRule ^(.*?)$ index.php?file=$1 [QSA,L]
I want to redirect every single request to index.php as a parameter:
files.domain.com/awesomefile.zip -> files.domain.com/index.php?file=awesomefile.zip
This works as expected, but if I enter http://files.domain.com/__admin or http://files.domain.com/admin (without trailing slash), it gets rewritten to http://files.domain.com/__admin/?file=__admin respectively http://files.domain.com/admin/?file=admin (same with other existing dirs). I know that mod_dir could be the culprit, but setting DirectorySlashes off in .htaccess doesn't have any effect.
- How do I get rid of the additional redirect (caused by mod_dir?) which adds the querystring to the URL? I want to completely hide the redirects from the user.
- Why does it even affect
admin(even though it isn't a directory)?
Edit: I'm sorry for being confusing, here are some examples which hopefully describe better what I mean:
User types:
http://files.domain.com/file.zip
User sees:http://files.domain.com/file.zip
Internal redirect:http://files.domain.com/index.php?file=file.zip
This is the desired behaviour.User types:
http://files.domain.com/admin/(note the trailing slash)
User sees:http://files.domain.com/admin/
Internal redirect:http://files.domain.com/index.php?file=admin/User types:
http://files.domain.com/admin
User sees:http://files.domain.com/admin/?file=admin<-- Why?
Internal redirect:http://files.domain.com/index.php?file=admin
The last example shows my problem. I want to get rid of the query string which the user shouldn't see!
http://files.domain.com/adminas well? It isn't a directory, and every other request works just fine.files.domain.com/awesomefile.zip, his URL bar still shows exactly the same URL as he typed in, but if he typeshttp://files.domain.com/admin, the querystring appears in his URL bar which shouldn't happen.?file=*though you are using the query string append[QSA]flag such that if a URI likeadmin?foo=barwas passed you would getindex.php?file=admin&foo=bar. Not sure if this is desired behavior or not. Your question is confusing though when you are talking about query strings being appended and there are none in your example.