簡體   English   中英

文件夾及其包含頁面的mod_rewrite

[英]mod_rewrite for folder and its containing pages

.htaccess代碼:

RewriteEngine on
RewriteRule ^articles/([-a-z]+)\.html$ articles/article.php?slug=$1 [L]

我有一個包含兩個頁面的文件夾[articles]:

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/ dir時,您的RewriteRule可能會選擇隱式的/articles/index.html

  1. 禁用每個:

      DirectoryIndex index.php 
  2. 或編寫一個自定義的RewriteRule來防止任何自動映射:

      RewriteRule ^articles/*$ articles/index.php [L] 
  3. 也可以Options -MultiViews禁用Options -MultiViews

    (在您的情況下,這可能不是問題。但是如果沒有RewriteLog / access.log摘錄,很難說出來。)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM