V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
plqws
V2EX  ›  Apache

请教一个 Apache 的 RewriteRule 问题

  •  
  •   plqws · 2015-12-19 13:33:22 +08:00 · 1592 次点击
    这是一个创建于 3041 天前的主题,其中的信息可能已经有所发展或是发生改变。
    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^/cache/
    RewriteRule ^(.*)$ /cache/$1
    #我想要如果匹配到 /cache/$1 的话就此结束
    #若没有匹配到 /cache/$1 的话就执行下面的那个 index.php
    RewriteRule ^ index.php [QSA,L]
    

    目录结构
    /root
    -cache
    |-test.txt
    -index.php
    -.htaccess

    比如访问 /test.txt ,就能直接访问到 /cache/test.txt ,若访问 /hello.txt 就重写成 /index.php?blahblahblah

    该如何实现呢?

    第 1 条附言  ·  2015-12-19 14:15:36 +08:00

    最后还是自己解决了

    RewriteEngine On
    
    RewriteRule !^cache/ cache%{REQUEST_URI}
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    
    RewriteRule ^ index.php [QSA,L]
    

    参考: http://stackoverflow.com/questions/1165341/apache-rewriterule-to-subdirectory

    1 条回复    2015-12-19 14:07:38 +08:00
    Slienc7
        1
    Slienc7  
       2015-12-19 14:07:38 +08:00
    [L]
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3361 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 12:37 · PVG 20:37 · LAX 05:37 · JFK 08:37
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.