静态内容的 Htaccess 不起作用!

发布于 2024-11-10 03:18:29 字数 1216 浏览 1 评论 0原文

因此,我设置了以下几行,以便将一些请求重定向到我的静态域:

RewriteEngine On
RewriteBase /

RewriteRule ^img/(.*)$ http://static.mydomain.com/img/$1 [R=301] 
RewriteRule ^css/(.*)$ http://static.mydomain.com/css/$1 [R=301]
RewriteRule ^js/(.*)$ http://static.mydomain.com/js/$1 [R=301,L]

但由于某种原因,当我链接到一张图片时:

<img src="img/icons/hello.png">

当它确实存在于静态服务器上时,它显示 404(这实际上意味着它是没有被重定向)。

我做错了什么?我花了大约两个小时尝试了我所知道的一切,但没有找到解决办法。

预先非常感谢您。这是我的完整 htaccess 文件:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    RewriteRule ^img/(.*)$ http://static.mydomain.com/img/$1 [R=301] 
    RewriteRule ^css/(.*)$ http://static.mydomain.com/css/$1 [R=301]
    RewriteRule ^js/(.*)$ http://static.mydomain.com/js/$1 [R=301,L]

    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    ErrorDocument 404 /index.php
</IfModule> 

So I setted up the following lines in order to redirect some requests to my static domain:

RewriteEngine On
RewriteBase /

RewriteRule ^img/(.*)$ http://static.mydomain.com/img/$1 [R=301] 
RewriteRule ^css/(.*)$ http://static.mydomain.com/css/$1 [R=301]
RewriteRule ^js/(.*)$ http://static.mydomain.com/js/$1 [R=301,L]

But for some reason, when I link to a, let's say, a picture:

<img src="img/icons/hello.png">

It's showing 404 when it really exists on static server (which actually means it's not being redirected).

What am I doing wrong? I spent like two hours trying everything I know but no fix found.

Thank you very much in advance. Here is my full htaccess file:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    RewriteRule ^img/(.*)$ http://static.mydomain.com/img/$1 [R=301] 
    RewriteRule ^css/(.*)$ http://static.mydomain.com/css/$1 [R=301]
    RewriteRule ^js/(.*)$ http://static.mydomain.com/js/$1 [R=301,L]

    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    ErrorDocument 404 /index.php
</IfModule> 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑着哭最痛 2024-11-17 03:18:29

调试重写的一种好方法是指定 RewriteLog 和 RewriteLogLevel。您将日志级别设置为 9,这会记录很多有关重写的内容。请记住在调试后禁用日志记录,因为它对于 apache 进程来说相当繁重。

RewriteLog 文档

One good way to debug the rewrites is to specify RewriteLog and RewriteLogLevel. You set log level up to 9 which logs quite a lot of things about the rewrites. Remember to disable the logging after debugging, because it is quite heavy for the apache process.

RewriteLog documentation

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文