douqian4411 2015-10-26 17:33
浏览 34

由于htaccess而难以访问子目录文件

This is my .htaccess code

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-s
    RewriteRule ^(.*)$ api.php?rquest=$1 [QSA,NC,L]

    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^(.*)$ api.php [QSA,NC,L]

    RewriteCond %{REQUEST_FILENAME} -s
    RewriteRule ^(.*)$ api.php [QSA,NC,L]

    RewriteCond %{REQUEST_URI} !^/images/   

</IfModule>

My directory structure:

Directory structure

My problem is that I can access my api.php by calling /users or /getData etc. But if I go for images/someImage.jpg then it not allowing.

  • 写回答

1条回答 默认 最新

  • dongpeixiong5943 2015-10-26 18:38
    关注

    Try this simple rewrite rule

    RewriteBase /your web directory
    

    RewriteEngine On

    RewriteRule ^([a-zA-Z0-9_-]+)$ api.php?rquest=$1

    RewriteRule ^([a-zA-Z0-9_-]+)/$ api.php?rquest=$1

    the following is the break down of the code

    RewriteBase / #enter your directory root here

    RewriteEngine On

    the following rewrite rule will redirect for example www.example.com/home to example.com/api.php?rquest=$1

    RewriteRule ^([a-zA-Z0-9_-]+)$ api.php?rquest=$1

    and the following will redirect for example www.example/home/ to example.com/api.php?rquest=$1. notice the / after /home

    RewriteRule ^([a-zA-Z0-9_-]+)/$ api.php?rquest=$1
    

    the above lines of code excludes the rule to redirect www.example.com/images/someimages.jpg to www.example.com/

    So this will work for now.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题