I made a dynamic sub folder using .htaccess, but the browser can't find the images in the root folder

67 views Asked by At

I made a dynamic folder this way:

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

I want the browser to look in the root folder for images. Currently it looks for them in example.com/user

2

There are 2 answers

0
RavinderSingh13 On

Could you please try following, its looking for if a uri is NOT ending with png format then redirect it to your index.php file, in case you have more formats like .jpg etc then change following regex from !\.png$ TO !(\.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]
2
Morten On

The answer was to do this:

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

Thanks for ideas, RavinderSingh13!