简体   繁体   English

htaccess重写规则后无法获取索引文件

[英]htaccess not get index file after rewrite rule

My htaccess is this : 我的htaccess是这样的:

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

So whenever browser get 'any thing' after root folder then it will go show.php and parameter will be 'any thing' . 因此,每当浏览器在root folder之后获取“任何东西”时,它将进入show.php并且参数将为“任何东西”。 Note: it will not effect if it have extension or a folder. 注意:如果具有扩展名或文件夹,则不会生效。

But there is index file in my root folder. 但是我的根文件夹中有索引文件。 So browser should take index file first. 因此浏览器应首先获取索引文件。 So that, i added this in .htaccess file : 因此,我在.htaccess文件中添加了此代码:

DirectoryIndex index.php 

But not working. 但是没有用。 So is there anything to do, to show at least index file whenever root folder visited ? 所以有什么事要做,只要在访问根文件夹时至少显示索引文件?

You can have your .htaccess like this: 您可以像这样使用.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