1

I use WampServer (Apache/PHP/MySQL) and I have the following files in my www directory:

  • www [dir]
    • test [dir]
    • index.php [file]
    • .htaccess [file]

I want to pass all URI requests as a parameter to index.php without causing any external redirects (location changes in client browser). So I tried to use the following rule:

RewriteRule ^(.*)$ index.php?path=$1 [nocase,qsappend,end]

Which works quite good, except when the URI is /test, in which case an external redirect changes the location to:

/test/?path=test

How can I make sure the external redirect does NOT happen even if the directory of the same name as the URI exists?


Expected result:

  • Original URI request: /test
  • Internal redirect: index.php?path=test
  • External redirect: none

Actual result:

  • Original URI request: /test
  • Internal redirect: index.php?path=test
  • External redirect: /test/?path=test

The ideal solution would be universal and would not apply only to test directory, but to any directory.

Paya
  • 5,124
  • 4
  • 45
  • 71
  • Put your code into a Virtual Host [See here for how to](http://stackoverflow.com/questions/23665064/project-links-do-not-work-on-wamp-server/23990618#23990618) – RiggsFolly Aug 24 '16 at 23:25
  • @RiggsFolly I just tried that and it made no difference at all. – Paya Aug 28 '16 at 20:32

1 Answers1

1

Ok the problem seems to be a conflict between mod_rewrite and mod_dir. Possible solutions are:

  1. Disable mod_dir
  2. Put this to .htaccess:

    <IfModule mod_dir.c>
         DirectorySlash Off
    </IfModule>
    

For more details about how mod_rewrite and mod_dir interact, this answer has some excellent info. And why the external redirect is necessary is explained in docs (Trailing Slash Problem).


Related links

Community
  • 1
  • 1
Paya
  • 5,124
  • 4
  • 45
  • 71