Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 静态内容的Htaccess不工作!_Php_Apache_.htaccess_Redirect_Http Status Code 301 - Fatal编程技术网

Php 静态内容的Htaccess不工作!

Php 静态内容的Htaccess不工作!,php,apache,.htaccess,redirect,http-status-code-301,Php,Apache,.htaccess,Redirect,Http Status Code 301,因此,为了将一些请求重定向到我的静态域,我设置了以下行: 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=

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

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> 

重新启动发动机
重写基/
重写规则^img/(*)$http://static.mydomain.com/img/$1[R=301]
重写规则^css/(*)$http://static.mydomain.com/css/$1[R=301]
重写规则^js/(*)$http://static.mydomain.com/js/$1[R=301,L]
重写COND%{REQUEST_URI}^系统*
重写规则^(.*)$/index.php?/$1[L]
重写cond%{REQUEST_URI}^应用程序*
重写规则^(.*)$/index.php?/$1[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)$index.php?/$1[L]
ErrorDocument 404/index.php

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


您确定在主httpd.conf中启用了mod_rewrite吗?明显的问题是:apache是否从解析.htaccess文件开始?AllowOverride设置为all?是的,它肯定会工作(其余规则按预期工作)。然而,它并没有重定向到静态!这很奇怪。我在工作项目中的重写规则看起来几乎相同:
RewriteRule^pictures/(*)$http://i.staticdomain.ru/pictures/$1[NC,L,R]
。您确定指定的
RewriteBase
正确吗
/
表示您的
img
URL如下所示:
http://yourdomain.com/img/someimage.jpg