0

我以这种方式制作了一个动态文件夹:

RewriteRule ^user/(.+)$ index.php?user=$1 [QSA]

我希望浏览器在根文件夹中查找图像。目前它在 example.com/user 中寻找它们

4

2 回答 2

1

您能否尝试以下操作,它会查找 uri 是否以pngformat 结尾,然后将其重定向到您的index.php文件,以防您有更多格式等,然后从TO .jpg更改以下正则表达式。!\.png$!(\.png|\.jpg)/?$

RewriteEngine ON
##First rule to skip .png files to go to index.php.
RewriteCond %{REQUEST_URI} !\.png/?$ [NC]
RewriteRule ^(.*)$ index.php?user=$1 [NC,NE,L]

##Second rule to serve .png files from images folder.
RewriteCond %{REQUEST_URI} !images [NC]
RewriteCond %{THE_REQUEST} \.png/?\s [NC]
RewriteRule ^(.*)$ /images/$1 [NE,L]
于 2020-11-15T20:39:50.900 回答
0

答案是这样做:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.+)$ index.php?user=$1 [QSA]

感谢您的想法,RavinderSingh13!

于 2020-11-15T20:47:05.277 回答