.htaccess代码:
RewriteEngine on
RewriteRule ^articles/([-a-z]+)'.html$ articles/article.php?slug=$1 [L]
我有一个文件夹[文章],里面有两页:
index.php和article.php
第一个页面显示文章列表,第二个页面实际使用参数[slug]从数据库中获取实际文章并显示
site.com/articles/this-is-an-article-title.html
site.com/articles/article.php?slug=this-is-an-article-title
代码运行良好,但问题是我看不到index.php上的文章列表,它错误地通过了RewriteRule。
我该如何阻止这种情况?
当请求articles/
目录时,RewriteRule可能会获取隐含的/articles/index.html
。
-
根据:禁用
DirectoryIndex index.php
-
或者编写一个自定义的RewriteRule来防止任何自动映射:
RewriteRule ^articles/*$ articles/index.php [L]
-
也可选择禁用
Options -MultiViews
(在您的情况下,这可能不是问题。但如果没有RewriteLog/access.log摘录,很难判断。)