Problems with .htaccess rewrite

Avatar
  • Answered
Hi There

On the shared hosting I have been trying to rewite my urls however I have come across a difficault situation with a very simple rule that may be as a result of mod_dir.

If I try to write my urls to a variable that I can use internally with PHP like so:

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?var=$1 [QSA,L]

Everything works great until the request conflicts with an actual folder path for example:

http://mydomain/conflict

sends my scripts var=conflict but... if there is a folder named 'conflict' firstly this happens:

http://mydomain/conflict/ (a forward slash is appened most likly a result of mod_dir)

And with my htaccess when the page is forwarded this happens:

http://mydomain/conflict/?var=conflict

This ofcourse reveals not only a directory presence but also any type of request string, I am unable to negate mod_dir in the htaccess rules and I'm not certain that switching off the forwardslash is a secure thing to do.

I have even tried -MultiViews in the htaccess with no luck, is there any way in the htaccess to force the server configuration to ignore certain folders when handling rewritten requests or is there some specific way to write this that doesnt conflict with the server configuration ?

Thanks :D

-------------------------------------------------
Update:

Additionally I posted this question logged in to my AMP account and recieved a reply from Scott M here:
https://www.inmotionhosting.com/support/community-support/how-to/htaccess-rewrite-conflict-directory

Hello,

While you can disable specific directives using htaccess, you may not be able to stop the behavior you are experiencing. Of course, on a shared server, the disabling of mod_dir is not possible.

Kindest Regards,
Scott M

Scott M linked 'specific directories' to this page:
http://httpd.apache.org/docs/trunk/mod/mod_dir.html

Having tried every single command in the htaccess to overide, each one returned and 'Internal Server Error', in short the shared user is not allowed to overide any directives to work arround the conflicting configuration of the server, therefore...

As in the origional question, is there any way to rewite everything to the scripts without the conflict when the rewite rule hits a directory ?.

Avatar
johnpaulb-imhs1
Hello, Thank you for contacting us. Disabling mod_dir is not possible on a shared server environment. You can make apache level changes on VPS and Dedicated servers. I am currently reviewing your .htaccess file for another possible workaround. I will post any additional information I am able to determine shortly. If you have any further questions, feel free to post them below. Thank you, John-Paul