Mod_rewrite invisibly: works when target is a file, not when it's a directory

前端 未结 1 1533
夕颜
夕颜 2021-01-14 11:57

I have this rewrite rule that turns foo.com/test (or foo.com/test/) into foo.com/test.txt:

RewriteRule ^test/?$ test.txt [NC,L]

It works pe

相关标签:
1条回答
  • 2021-01-14 12:33

    Add the trailing slash:

    RewriteRule ^test2/?$ testdir/ [NC,L]
    

    http://foo.com/testdir isn't a valid url to the directory, Apache looks for a file called testdir, and because testdir is actually a directory Apache tries to fix it by redirecting to testdir/ . So while your rewrite worked the subsequent missing slash error was fixed by redirecting to testdir/.

    You may also need to add a base href tag to the head of your document or relative links will break:

    <base href="/">
    
    0 讨论(0)
提交回复
热议问题