【问题标题】:htaccess redirecting issuehtaccess 重定向问题
【发布时间】:2009-11-02 21:48:21
【问题描述】:

我当前的 .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。

我怎样才能做到这一点?

【问题讨论】:

  • 应该移到 serverfault.com

标签: .htaccess mod-rewrite


【解决方案1】:

您的规则应该有效,因为它仅适用于请求的 URL 不能映射到现有文件 (!-f) 而不能映射到现有文件夹 (!-d)。因此,如果 /demo/test 是一个实际文件夹,则第二个条件 (RewriteCond %{REQUEST_FILENAME} !-d) 应该会失败。如果请求 /demo 并且既不是现有常规文件也不是现有文件夹,则应将其重定向到 /index.php/demo

【讨论】:

  • 要制作demo/test文件夹,显然我得制作一个叫demo的文件夹,并在里面创建一个文件夹test。
  • @Alec Smart:是的,-f-d 会导致真正的文件系统查找。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多