服务器忽略子目录htaccess文件,直接进入root htaccess

时间:2013-01-29 13:46:21

标签: .htaccess codeigniter mod-rewrite url-rewriting rewrite

我有一个使用Codeigniter和SLIR(Smart Lencioni Image Resizer https://github.com/lencioni/SLIR)的应用程序。 SLIR允许您使用直观的URI结构调整图像大小。例如:

<img src="/slir/w100-h100/path/to/image.jpg"/>

这会调整图像大小以适应100px * 100px。无论出于何种原因,当我尝试查看已调整大小的图像时,(例如http://a2op03.com/slir/w300-h90/images/content/franchise-opportunities-badge.png)我收到Codeigniter生成的404错误。我已经验证了以下内容:

Codeigniter [root] htaccess文件如下所示:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #When your application folder isn't in the system folder
    #This snippet prevents user access to the application folder
    #Submitted by: Fabdrol
    #Rename 'application' to your applications folder name.
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php
</IfModule>

和/ slir /中的htaccess文件如下所示:

# Prevent other scripts from interfering with SLIR
php_value auto_prepend_file none
php_value auto_append_file none

# Pretty URLs
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [S=40]
RewriteRule . index.php [L]
</IfModule>

# Prevent viewing of the error log file in its default location
<Files slir-error-log>
Order Deny,Allow
Deny from All
</Files>

我最初的怀疑是mod_rewrite.c没有正确设置,因此没有被SLIR htaccess处理并且回退到根htaccess,它将它发送到404.我通过servint在托管的VPS上托管.net并让WHM具有对服务器的完全访问权限。主持人声称mod_rerwrite应该正常工作。我在另一台服务器上完美地工作,但我无法弄清楚为什么它不能在这里工作。任何帮助表示赞赏!

1 个答案:

答案 0 :(得分:2)

我明白了!我只需要添加

RewriteBase /slir/

RewriteEngine On

在SLIR的htaccess文件中!