【发布时间】:2011-05-30 04:31:07
【问题描述】:
所以我设置了以下几行,以便将一些请求重定向到我的静态域:
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>
【问题讨论】:
-
您确定在您的主 httpd.conf 中启用了 mod_rewrite 吗?
-
显而易见的问题:Apache 是否开始解析您的 .htaccess 文件? AllowOverride 设置为全部?
-
是的,它确实有效(其余规则按预期工作)。但是,它不会重定向到静态!
-
这很奇怪。我在工作项目中的 RewriteRules 看起来几乎相同:
RewriteRule ^pictures/(.*)$ http://i.staticdomain.ru/pictures/$1 [NC,L,R]。您确定您正确指定了RewriteBase吗?/表示您的imgURL 如下所示:http://yourdomain.com/img/someimage.jpg
标签: php apache .htaccess redirect http-status-code-301