Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.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
.htaccess htaccess在特定目录中将PNG重写为JPG_.htaccess_Png_Rewrite_Jpeg - Fatal编程技术网

.htaccess htaccess在特定目录中将PNG重写为JPG

.htaccess htaccess在特定目录中将PNG重写为JPG,.htaccess,png,rewrite,jpeg,.htaccess,Png,Rewrite,Jpeg,基本上,我将站点上的图像生成从PNG更改为JPG,并转换所有现有文件以节省空间。问题在于对旧PNG版本的请求 这只影响了一些特定的目录,例如/imgs/profiles/ 我自己也试着去理清规则,但这快把我逼疯了 如果有人能给我一个在/imgs/profiles/中将PNG请求重写为JPG的例子,为了节省空间,我可以对其余的进行排序 编辑-我的htaccess顶部的部分 FileETag None Options +FollowSymLinks -MultiViews RewriteEngine

基本上,我将站点上的图像生成从PNG更改为JPG,并转换所有现有文件以节省空间。问题在于对旧PNG版本的请求

这只影响了一些特定的目录,例如/imgs/profiles/

我自己也试着去理清规则,但这快把我逼疯了

如果有人能给我一个在/imgs/profiles/中将PNG请求重写为JPG的例子,为了节省空间,我可以对其余的进行排序

编辑-我的htaccess顶部的部分

FileETag None
Options +FollowSymLinks -MultiViews
RewriteEngine On

RewriteCond %{HTTP_HOST} !^www.site.net
RewriteRule (.*) http://www.site.net/$1 [R=301,L]

ErrorDocument 404 /404.php
ErrorDocument 300 /404.php

RewriteBase /imgs/profiles/
RewriteRule ^([^.]+)\.png$ /$1.jpg [R=301,L,NC]

RewriteRule ^file file.php [L,NC]

通过
httpd.conf
启用mod_rewrite和.htaccess,然后将此代码放入
.htaccess
目录下的
$DOCUMENT\u ROOT/imgs/profiles
目录下:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /imgs/profiles/

RewriteRule ^([^.]+)\.png$ /imgs/profiles/$1.jpg [R=301,L,NC]
编辑:我正在为您的.htaccess提供修复程序,请点击此处: 确保此.htaccess直接位于您的
$DOCUMENT\u ROOT
目录下:

FileETag None
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /

ErrorDocument 404 /404.php
ErrorDocument 300 /404.php

RewriteCond %{HTTP_HOST} !^www\.site\.net$ [NC]
RewriteRule ^(.*)$ http://www.site.net/$1 [R=301,L]

RewriteRule ^(imgs/profiles/[^.]+)\.png$ /$1.jpg [R=301,L,NC]

RewriteRule ^file/?$ /file.php [L,NC]

嗯,当我应用时,它确实重写为jpg,但目录不正确对/imgs/profiles/6.png的请求导致/imgs/profiles/imgs/profiles/6.jpgAha更改了RewriteRule^([^.]+)\.png$/imgs/profiles/$1.jpg[R=301,L,NC]以重写rule^([^.]+)\.png$/$1.jpg[R=301,L,NC]工作,我想是因为重写后的基是root是的,关于base root你是对的。很高兴它对您有效。嗯,它在本地有效,但htaccess中的其他请求也指向/imgs/profiles://@FaTe请将您的解决方案添加为新答案。