繁体   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