H
H
Hazrat Hajikerimov2014-10-26 04:52:31
Apache HTTP Server
Hazrat Hajikerimov, 2014-10-26 04:52:31

Redirecting with Apache?

In general, such a thing, there are pages on the site where pictures are connected in the following path /images/file_name.extension.
The problem is that I moved this folder to public and now I need to make a redirect using apache when accessing the /images/ folder to /public/images/filename .

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
Wimbo, 2014-10-26
@Wimbo

# 301 --- www.test.com/images => www.test.com/public/images
RewriteRule ^images/$ /public/images/? [L,R=301]
isn't it? in .htaccess

T
truekenny, 2014-10-26
@truekenny

# Вариант 1, без переадресации 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.?images/(.+)$ public/images/$1

# Вариант 2, с переадресацией
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.?images/(.+)$ /public/images/$1 [R,L]

1. A request for a non-existent /images/1.jpg file will return the contents of /public/images/1.jpg;
2. A request for a non-existent /images/1.jpg file will receive a response that it should be searched for at /public/images/1.jpg, that is, a redirect will be performed (2 requests to the server in total).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question