簡體   English   中英

htaccess重寫規則后無法獲取索引文件

[英]htaccess not get index file after rewrite rule

我的htaccess是這樣的:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^([0-9a-zA-Z-]+)?$ show.php?id=$1 [L]
</IfModule>

因此,每當瀏覽器在root folder之后獲取“任何東西”時,它將進入show.php並且參數將為“任何東西”。 注意:如果具有擴展名或文件夾,則不會生效。

但是我的根文件夾中有索引文件。 因此瀏覽器應首先獲取索引文件。 因此,我在.htaccess文件中添加了此代碼:

DirectoryIndex index.php 

但是沒有用。 所以有什么事要做,只要在訪問根文件夾時至少顯示索引文件?

您可以像這樣使用.htaccess:

DirectoryIndex index.php

RewriteEngine On

# request is not for a file
RewriteCond %{REQUEST_FILENAME} !-f
# request is not for a directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9a-zA-Z-]+)/?$ /show.php?id=$1 [L,QSA]

暫無
暫無

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

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