douju2474
2017-04-11 09:43
浏览 193
已采纳

.htaccess重写文件夹路径的文件路径

I have a subdirectory contact and inside contact.php and contact_content.php and .htaccess file

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]

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

图片转代码服务由CSDN问答提供 功能建议

我有一个子目录联系人,里面有contact.php和contact_content.php和.htaccess文件

在.htaccess文件中我有以下代码:

 选项+ FollowSymLinks 
RewriteEngine on 
 
RewriteCond%{REQUEST_URI} ^ / contact / contact.php \  nRewriteRule ^ / contact [R = 301,L] 
 
RewriteRule ^ / $ contact.php [NC,L,END] 
 
 #deny access 
RewriteRule ^(contact_content)\ .php  -  [F,L,  NC] 
   
 
 

拒绝访问部分和第一个重写规则完美地工作,但问题是第二个重写 - > 当我去 localhost / contact 时,我会在联系人目录中显示文件列表,而不是 contact.php site

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongmu3187 2017-04-11 11:46
    已采纳

    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]
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • dqthn68688 2017-04-11 09:58

    Hopefully it will work fine.

    RewriteEngine On
    
    Options -Indexes
    RewriteCond %{REQUEST_URI} contact\.php$
    RewriteRule ^(.*)$ /contact [R=301]
    
    
    RewriteCond %{REQUEST_URI} ^/contact/?$
    RewriteRule ^(.*)$ /$1/contact.php [L,QSA,END]
    
    RewriteRule ^(contact_content)\.php - [F,L,NC]
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题