首页 文章

简单的.htaccess重写规则不起作用

提问于
浏览
2

我有以下.htaccess文件 . 它拒绝访问以下url结构:

www.example.com/test

即使它访问这个罚款:

www.example.com/test.php

我使用这个文件运行了一些更复杂的重写规则,它运行得很好 . 例如:

RewriteRule ^ tests /([0-9])/?$ /tests_page.php?id=$1 [PT,L,QSA]

我不明白这是怎么回事 . 我在这里错过了什么?

#OPTIONS
Options -Indexes
Options +FollowSymLinks

#ACCESS TO THE .HTACCESS FILE
<Files .htaccess>
order allow,deny
deny from all
</Files>

#REWRITE ENGINE
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteEngine On

#PAGES REWRITE
RewriteRule ^test/?$ /test.php

Update:

我将该文件重命名为tests.php并将规则更改为this并且它有效:

RewriteRule ^ test /?$ /tests.php

这仍然无法解释为什么会发生这种情况 .

为什么我不能将url文件夹名称与文件名匹配?

1 回答

  • 3

    这似乎是 MultiViews 选项的问题 . 使用以下命令禁用它:

    Options -MultiViews
    

    .htaccess顶部的一行 . 选项 MultiViewsApache's content negotiation module 使用,它在 mod_rewrite 模块之前运行,并使Apache服务器匹配文件扩展名 . 所以 /file 可以在URI中,但它将提供 /file.php .

相关问题