【问题标题】:Ignore specific URL in .htaccess忽略 .htaccess 中的特定 URL
【发布时间】:2015-02-26 01:08:51
【问题描述】:

我的 .htaccess 文件中有一组标准的 WordPress 重写:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

但我想避免对特定 URL 进行任何重写,即:

http://www.domain.com/wp-content/themes/jarvis_wp/css/i?w=400&amp;h=250

我尝试在 WordPress 重写之上添加此规则:

RewriteRule ^css - [L,NC]

但这似乎不起作用。如何让浏览器加载该 URL 而无需任何重写?

这是“i”文件夹内的 index.php 文件中的代码,也许这可能与重定向有关,我不确定它来自哪里:

<?php
// Include placeholder generator class
require('placeholder.class.php');

// Get variables from $_GET
$width           = isset($_GET['w']) ? trim($_GET['w']) : null;
$height          = isset($_GET['h']) ? trim($_GET['h']) : null;
$backgroundColor = isset($_GET['bgColor']) ? strtolower(trim($_GET['bgColor'])) : null;
$textColor       = isset($_GET['textColor']) ? strtolower(trim($_GET['textColor'])) : null;
$cache           = isset($_GET['c']) && $_GET['c'] == 1 ? true : false;

try {
    $placeholder = new Placeholder();
    $placeholder->setWidth($width);
    $placeholder->setHeight($height);
    $placeholder->setCache($cache);
    if ($backgroundColor) $placeholder->setBackgroundColor($backgroundColor);
    if ($textColor) $placeholder->setTextColor($textColor);
    $placeholder->render();
} catch (Exception $e){
    die($e->getMessage());
}

谢谢!

【问题讨论】:

    标签: apache .htaccess mod-rewrite


    【解决方案1】:

    代替

    RewriteRule ^css - [L,NC]
    

    试试

    RewriteRule ^wp-content/themes/jarvis_wp/css/i - [L]
    

    【讨论】:

    • 嗯,这些建议都不适用于这种情况。我想知道重定向是否没有发生在 .htaccess 级别。我将在我原来的问题中发布“i”文件夹的 index.php 文件的内容。
    【解决方案2】:

    您可以告诉它忽略 wp-content 文件夹,这样它就不会进行重写。

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_URI} !^/wp-content [NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    

    【讨论】:

    • 查看下面的相同评论。
    • 您的 htaccess 文件的位置在哪里?
    • 网站根目录
    • 尝试清除浏览器缓存或尝试使用其他浏览器。该规则应该有效。
    • 我已经完成了,但仍然无法正常工作。要么我这里有问题,要么重定向没有通过 .htaccess 发生。我可以在这里发布真实的 URL,但我认为 Stack Overflow 不喜欢这种东西。
    猜你喜欢
    • 2013-10-02
    • 2018-09-27
    • 1970-01-01
    • 1970-01-01
    • 2016-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-30
    相关资源
    最近更新 更多