Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.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重写-排除条件中的某些文件夹_.htaccess_Mod Rewrite - Fatal编程技术网

.htaccess Htaccess重写-排除条件中的某些文件夹

.htaccess Htaccess重写-排除条件中的某些文件夹,.htaccess,mod-rewrite,.htaccess,Mod Rewrite,我有一个脚本,可以在图像上放置水印 我想要一个重写规则,它将排除文件夹中的图像(thumb和thumbprofile)。这意味着此文件夹中的图像将不会加盖水印 现在我有这个 RewriteRule ^([^/thumb|^/profilethumb].*\.(gif|jp?g|png))$ watermark.php?image=$1&watermark=watermark.png [NC] 问题是它没有在(thumb)中的图像上添加水印,这是正确的,但它仍然在文件夹(profilet

我有一个脚本,可以在图像上放置水印

我想要一个重写规则,它将排除文件夹中的图像(thumb和thumbprofile)。这意味着此文件夹中的图像将不会加盖水印

现在我有这个

RewriteRule ^([^/thumb|^/profilethumb].*\.(gif|jp?g|png))$ watermark.php?image=$1&watermark=watermark.png [NC]

问题是它没有在(thumb)中的图像上添加水印,这是正确的,但它仍然在文件夹(profilethumb)中标记水印。

也许这就是您需要的:

Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI}  !/(thumb|profilethumb) [NC]
RewriteCond %{REQUEST_URI}  !watermark\.php        [NC]
RewriteCond %{REQUEST_URI}  /([^.]+)\.(gif|jpg|jpeg|png) [NC]
RewriteRule .*  /watermark.php?image=%1.%2&watermark=watermark.png [NC,L]

我猜在
/thumb
/profilethumb
中只有图像,将这两个目录从规则中排除就足够了。如果还有其他文件,我想你也不希望它们有水印。

也许这就是你需要的:

Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI}  !/(thumb|profilethumb) [NC]
RewriteCond %{REQUEST_URI}  !watermark\.php        [NC]
RewriteCond %{REQUEST_URI}  /([^.]+)\.(gif|jpg|jpeg|png) [NC]
RewriteRule .*  /watermark.php?image=%1.%2&watermark=watermark.png [NC,L]

我猜在
/thumb
/profilethumb
中只有图像,将这两个目录从规则中排除就足够了。如果还有其他文件,我认为您也不希望它们具有水印。

请结合以下条件尝试此规则:

RewriteCond %{REQUEST_URI} !^/(profile)?thumb(/.*)?$ [NC]
RewriteRule ^.*\.(gif|png|jpe?g)$ watermark.php?image=$0&watermark=watermark.png [L,NC]

结合以下条件尝试此规则:

RewriteCond %{REQUEST_URI} !^/(profile)?thumb(/.*)?$ [NC]
RewriteRule ^.*\.(gif|png|jpe?g)$ watermark.php?image=$0&watermark=watermark.png [L,NC]

您可以首先使用不替换URL路径的a跳过两个目录
thumb
profilethumb
,然后使用第二个规则处理所有其他图像

RewriteRule ^(?:thumb|profilethumb).*\.(?:gif|jpe?g|png)$ - [L,NC]
RewriteRule ^.*\.(?:gif|jpe?g|png)$ watermark.php?image=$0&watermark=watermark.png [L,NC]

您可以首先使用不替换URL路径的a跳过两个目录
thumb
profilethumb
,然后使用第二个规则处理所有其他图像

RewriteRule ^(?:thumb|profilethumb).*\.(?:gif|jpe?g|png)$ - [L,NC]
RewriteRule ^.*\.(?:gif|jpe?g|png)$ watermark.php?image=$0&watermark=watermark.png [L,NC]

只有那两个文件夹上的图像。我的回答中的规则应该有效。我修改了几次,因为有些地方不对劲,所以决定只排除目录。只排除2 foldersOkay上的图像。我的回答中的规则应该有效。我修改了几次,因为有些地方不对劲,所以决定只排除目录。