C
C
ChiPer2014-03-04 08:45:05
Apache HTTP Server
ChiPer, 2014-03-04 08:45:05

mod_rewrite: how to hide folder in url?

The question is.
The site has a folder with pictures:
site.com/images
It has categories:

http://site.com/images/banners/
http://site.com/images/monitors/
http://site.com/images/computers/
http://site.com/images/notebooks/

Categories are constantly being added. (I'm ready to edit .htaccess with my hands every time).
Those. many subfolders.
How can I make it so that when accessing, for example, a picture in the monitors category:
For example: site.com/images/monitors/img.jpg
The 'images' folder does not appear?
That is, when requesting:
site.com/monitors/img.jpg
The image should be returned with url ( site.com/images/monitors/img.jpg)
.htaccess:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule ^images/(.+)$ http://site.com/$1 [R=301,L]

Does not work.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vit, 2014-03-04
@fornit1917

I can’t check if it works now, but the logic should be something like this:
RewriteRule ^cat([0-9]+)/(.+)$ site.com/images/cat$1/$2 [R=301,L]

Q
q1t, 2014-03-04
@q1t

RewriteEngine on
RewriteBase /
RewriteRule ^img/(.+)$ images/$1 [NC,L]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question