【问题标题】:Htaccess friendly SEO rewrite made images stop loading?Htaccess 友好的 SEO 重写使图像停止加载?
【发布时间】:2011-12-20 20:26:11
【问题描述】:

我使用生成器让我的 SEO 友好的 htaccess 重写,就是这样。

RewriteRule ^([^/]*)/([^/]*) /detail.php?type=$1&?id=$2 [L]

输出应该是 www.site.com/type/id

现在,重写工作正常,页面重定向正常,但网站上的图像不再显示,它们都坏了...... :( 图像的 URL 是正确的,但似乎它只是不想加载了,有什么帮助吗?是否应该有另一个重写规则来取消这个规则来做其他事情?如果是这样,什么?

【问题讨论】:

    标签: .htaccess seo


    【解决方案1】:

    您现有的规则可能会影响图像。为防止这种情况发生,请使用 RewriteCond 指令,该指令将排除受规则影响的图像等扩展名。您可以根据需要添加其他扩展名。

    #if its not an image, css, js etc
    RewriteCond %{REQUEST_URI} !\.(gif|jpg|png|css|js|etc)$ [NC]
    RewriteRule ^([^/]*)/([^/]*) /detail.php?type=$1&?id=$2 [L]
    

    【讨论】:

      【解决方案2】:

      我不确定您的 .htaccess 是什么样子,但这里有一些我在项目中使用的方便规则,它非常简单并且涵盖了大部分问题:

      <IfModule mod_rewrite.c>
          ############################################
          # Enable mod_rewrite
          RewriteEngine On
          RewriteBase /
      
          ############################################
          ## always send 404 on missing files in these folders
          RewriteCond %{REQUEST_URI} !^/(media|assets)/
      
          ############################################
          # never rewrite for existing files, directories and links
          RewriteCond %{REQUEST_FILENAME} !-f
          RewriteCond %{REQUEST_FILENAME} !-d
          RewriteCond %{REQUEST_FILENAME} !-l
      
          RewriteRule .*$ index.php [L]
      </IfModule>
      

      【讨论】:

      • 谢谢!这不适用于我的具体情况,但它似乎对我的其他项目很有用,我会使用它!
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-07-06
      • 2015-01-04
      • 1970-01-01
      • 2015-02-14
      • 2019-06-07
      • 1970-01-01
      • 2014-08-23
      相关资源
      最近更新 更多