.htaccess将文件路径重写为文件夹路径
问题描述:
我有一个子目录contact,位于contact.php和contact_content.php和.htaccess文件中
I have a subdirectory contact and inside contact.php and contact_content.php and .htaccess file
在.htaccess文件中,我有以下代码:
In .htaccess file I have following code:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/contact/contact.php
RewriteRule ^ /contact [R=301,L]
RewriteRule ^/$ contact.php [NC,L,END]
# deny access
RewriteRule ^(contact_content)\.php - [F,L,NC]
拒绝访问部分和第一个重写规则可以正常工作,但是
问题是第二次重写->当我转到localhost/contact
时,系统显示联系人目录中的文件列表,而不是contact.php
网站
Deny access part and the first rewrite rule work perfectly but
the problem is the second rewriterule-> when I go to localhost/contact
I am shown the list of files in contact directory instead of contact.php
site
答
这对我有用->修改过的Sahil Gulati答案
This works for me-> modified Sahil Gulati answer
Options +FollowSymLinks -Indexes
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/contact/contact.php
RewriteRule ^ /contact [R=301,L]
RewriteCond %{REQUEST_URI} ^/contact/?$
RewriteRule ^(.*)$ /contact/contact.php [L,QSA,END]
RewriteRule ^(contact_content)\.php - [F,L,NC]