【问题标题】:Mod_Rewrite rewriting directory I dont want it toMod_Rewrite 重写目录我不希望它
【发布时间】:2013-01-30 15:29:53
【问题描述】:

所以我正在使用 Kohana,如果你知道的话它很有用,但不需要帮助我。

我有以下 mod_rewrite 规则:

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/store/.*$

# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php [L]

所以我正在尝试将所有对不存在的文件和目录的请求重写为index.php

但是,我希望发送到 mydomain.com/store/* 的任何请求都能通过,因为在 store 目录中有另一个 htaccess 文件在那里工作。目前这似乎不起作用。有什么想法吗?

完整的htaccess:

# Turn on URL rewriting
RewriteEngine On

# Installation directory
RewriteBase /

#ErrorDocument 404 http://www.mydomain.com/404Page.html
#Options +FollowSymlinks

# Protect hidden files from being viewed
<Files .*>
    Order Deny,Allow
    Deny From All
</Files>


RewriteCond %{REMOTE_ADDR} !^myip
RewriteCond %{REQUEST_URI} !^/maintenance\.html$
RewriteRule ^(.*)$ http://www.mydomain.com/maintenance.html [R=307,L]

##301 Redirect Rules##
#some 301 redirects i did not include here

##Kohana Redirect Rules##

# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system|kohana|vendors)\b.* http://www.mydomain.com/ [L]

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/?store/

# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php [L]

【问题讨论】:

  • 注意我也尝试了以下规则RewriteRule ^store - [L,NC]
  • 如果/store 是一个物理目录,那么!-d 检查就足够了,/store 条件就不需要了。其他地方出了点问题。
  • @SalmanA 你是绝对正确的。我是个白痴,并没有查看实际商店目录中的 htaccess 文件

标签: apache mod-rewrite kohana


【解决方案1】:

试试这个条件:

RewriteCond %{REQUEST_URI} !^/?store/

目录后面的字符无需检查。如果我没记错的话,我将第一个斜杠设为可选,只有当您的服务器配置不包含尾部斜杠时,第一个斜杠才可见。

【讨论】:

  • 不,它还在做。我要发布完整的文件,也许我在这里还缺少其他东西
【解决方案2】:

问题出在store 目录中的.htaccess 文件中,而不是webroot 中的那个。谢谢大家,并为我的愚蠢感到抱歉。如果有人想让 cmets 了解如何为未来的用户调试这种性质的东西,那就太棒了。

【讨论】:

    猜你喜欢
    • 2016-08-31
    • 1970-01-01
    • 2012-06-26
    • 2021-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多