代码之家  ›  专栏  ›  技术社区  ›  Antony Carthy

Mod Rewrite忽略-d

  •  0
  • Antony Carthy  · 技术社区  · 15 年前

    一两天后,我仍在与Mod Rewrite抗争。似乎我60%的开发时间都花在了服务器上。

    我当前的URL结构是这样的 http://example.com/xyz http://example.com/xyz/abc http://example.com/admin/ 节,这是一个 实目录 我需要通过HTTP请求访问它(它是CMS目录)

    当我尝试浏览到CMS时 ,它将我的URL更改为 http://example.com/admin/?n=admin 并返回一个404。My index.php正在接收n=admin作为其参数。

    我不明白的是,为什么这两个条件被忽略了:

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !^admin(?:\/)?$
    

    为什么我要把它重定向到 (而不是仅仅停留在 http://example.com/admin/

    Options +FollowSymlinks
    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !^admin(?:\/)?$
    
    # allow access to certain subdirectories.
    RewriteRule ^admin(?:\/)?$ /admin/ [L,NC]
    
    # redirect all old URLs to new pages (or 404 sitemap page if no analog?).
    RewriteRule ^company/about(?:\/)?$ /company [R=301,L,NC]
    
    # catch any others and try to serve them right
    RewriteRule ^/?(.+).html$ /$1 [R=301,L]
    
    RewriteRule ^/?([0-9]+)(?:\/)?$ /index.php?p=$1 [L]
    RewriteRule ^/?([-a-zA-Z0-9_+]+)(?:\/)?$ /index.php?n=$1 [L]
    RewriteRule ^/?([-a-zA-Z0-9_+]+)/([-a-zA-Z0-9_+]+)(?:\/)?$ /index.php?n=$2 [L]
    

    2 回复  |  直到 15 年前
        1
  •  0
  •   Simeon Pilgrim    15 年前

    每个重写条件仅应用下一个重写规则。

    所以只有你的第一条规则有一个条件。

        2
  •  0
  •   Gumbo    15 年前

    请先尝试此规则,然后再尝试其他规则:

    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    

    -f 相反