本文介绍了.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]更多推荐
.htaccess将文件路径重写为文件夹路径
发布评论