Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.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_Mod Rewrite - Fatal编程技术网

Php 是否可以更改子域';是使用.htaccess的目录吗?

Php 是否可以更改子域';是使用.htaccess的目录吗?,php,apache,.htaccess,mod-rewrite,Php,Apache,.htaccess,Mod Rewrite,我有一个图像共享网站,我曾经有一个子域名的图像,但我不得不删除它,所以现在我使用一个真正的路径到图像: 旧url: http://img.site.com/images/2013/03/abc.jpg http://site.com/files/images/2013/03/abc.jpg 新网址: http://img.site.com/images/2013/03/abc.jpg http://site.com/files/images/2013/03/abc.jpg 问题是,我有很

我有一个图像共享网站,我曾经有一个子域名的图像,但我不得不删除它,所以现在我使用一个真正的路径到图像:

旧url:

http://img.site.com/images/2013/03/abc.jpg
http://site.com/files/images/2013/03/abc.jpg
新网址:

http://img.site.com/images/2013/03/abc.jpg
http://site.com/files/images/2013/03/abc.jpg
问题是,我有很多图片是从其他网站和搜索引擎链接而来的,它们仍然使用旧的URL

旧子域的问题是它的目录(
public\u html/files
)和名称(
img.
)不同,因此需要特殊配置来处理这个问题,我厌倦了它造成的所有问题

现在我已经创建了一个普通的
img.
子域,它指向
public\u html/img
目录,因此不需要额外的配置,但是我的图像仍然在
public\u html/files
目录中

我想我现在所要做的就是使用.htacess将新目录替换为旧目录。我不知道这是否可能

我的
.htaccess
当前为:

<IfModule mod_rewrite.c>

    RewriteEngine On

    RewriteBase /
    RewriteCond %{HTTP_HOST} ^img\.site\.com$ [NC]
    RewriteRule ^(images/.*)$ http://site.com/files/images/$1[R=301,NC,L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{ENV:REDIRECT_STATUS} ^$

    RewriteRule ^(.*)$ index.php/$1 [L,QSA] 
</IfModule>
我的错误日志报告:

[Mon Oct 21 02:58:46 2013] [error] [client 85.185.229.221] script '/home/site/domains/site.com/public_html/img/index.php' not found or unable to stat

你应该重定向到正确的位置。在
public\u html/img
目录下的htaccess文件中,执行以下操作:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^img\.site\.com$ [NC]
RewriteRule ^images/(.*)$ http://site.com/files/images/$1 [L,R=301]
或者只是

Redirect 301 /images http://site.com/files/images
好的,试试这个:

RewriteEngine On RewriteCond %{HTTP_HOST} ^img\.your-domain\.com$ [NC] RewriteRule ^images/(.*)$ /files/images/$1 [L,R=301] 重新启动发动机 RewriteCond%{HTTP_HOST}^img\.your domain\.com$[NC] 重写规则^images/(.*)$/files/images/$1[L,R=301]
您修改的.htaccess看起来像(假设它位于文档根
/


重新启动发动机
RewriteCond%{HTTP_HOST}^img\.site\.com$[NC]
重写规则^(图像/*)$http://site.com/files/$1[R=301,北卡罗来纳州,北卡罗来纳州]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)$index.php?/$1[L]

RewriteCond
首先检查域,如果域是旧的
img.site.com
,则将所有
/images
请求重定向到新的URL

我可以提供一个间接的解决方案,您需要在页眉或页脚文件中做一些更改,为此,请在.htaccess中的下面几行键入

HeaderName /path/.../header.html (if .html) or if .php header then,

AddType text/html .php
Addhandler application/x-httpd-php .php
HeaderName /path/.../header.php
或者只需为footer指定ReadmeName/path/../footer.html,
然后在该文件中使用copy+unlink(用于移动文件,但速度较慢),(或者确切地说,重命名()是更好的选择),以完成任务

有没有办法在规则中包含子域?在我的子目录中(例如在
资产
目录中)有许多其他
图像
目录,使用此规则会把它们搞乱。我已尝试将
^images/(.*)$
更改为
^site.com/images/(.*)$
,但无效。如果您为域img.site.com指定了专用vhost,您可以添加上述重定向到vhost,而不是.htacces,然后,它将仅适用于对img.site.com/images的请求,而不是所有请求*/images@max您可以通过在条件匹配(请参见编辑)thanx中使用
%{HTTP_HOST}
变量来包含子域,我已经更新了我的htacc并在底部添加了结果是的,我将在我们说话的时候查看它,也许这与……有关。。。。thanx(1)您的htaccess是否在
/public\uHTML
中?(2) 确保
$[R=301,NC,L]
(3)是您试图以
http://img.site.com/images/2013/10/image.jpg
当您转到
http://site.com/files/images/2013/10/image.jpg
?1-是,2-是,3-是的,我认为当您创建子域时,您的cpanel所做的任何配置都会干扰htaccess规则。如果您启用了通配符dns(即
*.site.com
指向
site.com
),您也可以从
anything.site.com
访问站点主页。您可以尝试设置
images.site.com
htaccess
规则,看看这些文件是否可以访问吗?基本上,我想把任何迫使
img.site.com
通过
/img
的服务器配置从等式中拉出来。你能启用
RewriteLog
并将日志发布到这里吗。还有
RewriteRule^(images/*)$http://site.com/files/images/$1[R=301,NC,L]
需要一些更正,因为
重写规则^(图像/+)$ http://site.com/files/$1[R=301,NC,L]
。请确保您正在使用新浏览器对其进行测试。@anubhava我已尝试在
httpd.conf
中启用
RewriteLog
,方法是将
Loglevel Warn
更改为
Loglevel alert rewrite:trace3
。。。。但是,当我重新启动apache时,我收到一个错误
/sbin/service httpd restart 2>&1
,显然它不起作用,或者我做错了什么请参阅此链接以启用重写日志:您是否在我的评论中尝试了上面建议的规则。