代码之家  ›  专栏  ›  技术社区  ›  Alec Smart

htaccess重定向问题

  •  -1
  • Alec Smart  · 技术社区  · 16 年前

    我当前的.htaccess:

    <IfModule mod_rewrite.c>
    # Turn on URL rewriting
    RewriteEngine On
    
    # Put your installation directory here:
    # If your URL is www.example.com/, use /
    # If your URL is www.example.com/kohana/, use /kohana/
    RewriteBase /
    
    # Do not enable rewriting for files or directories that exist
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    
    # For reuests that are not actual files or directories,
    # Rewrite to index.php/URL
    RewriteRule ^(.*)$ index.php/$1 [PT,L]
    
    
    </IfModule>
    

    http://mysite.com/demo/test

    http://mysite.com/demo 我想让它们转到index.php/$1。

    我怎样才能做到这一点?

    1 回复  |  直到 6 年前
        1
  •  0
  •   Gumbo    16 年前

    您的规则应该有效,因为它仅在请求的URL无法映射到现有文件时应用( !-f )而不是现有文件夹( !-d ).那么如果 /demo/test RewriteCond %{REQUEST_FILENAME} !-d )应该失败。如果 /demo 已请求,并且既不是现有的常规文件,也不是应重定向到的现有文件夹 /index.php/demo

    推荐文章