静态内容的 Htaccess 不起作用!
因此,我设置了以下几行,以便将一些请求重定向到我的静态域:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
调试重写的一种好方法是指定 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