.htaccess将文件路径重写为文件夹路径

编程入门 行业动态 更新时间:2024-10-24 16:28:01
本文介绍了.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将文件路径重写为文件夹路径

本文发布于:2023-11-01 23:06:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1550673.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路径   重写   文件夹   文件   htaccess

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!