D
D
Denis Shpuganich2014-07-04 10:57:07
htaccess
Denis Shpuganich, 2014-07-04 10:57:07

RewriteRule - How to correctly implement an internal redirect?

It is necessary to modify the url before it is processed by the router:
For example, the url is requested:
/img/100x100/images/ddde721137e7ea40a5754b70037425bc.jpg
you need to convert it to
/img?w=100&h=100&src=images/ddde721137e7ea40a5754b70037425
if 3=Rb.2] , then everything works, but if only [L] the original url is sent to the router, which is not clear.
In theory, after all, it should be transformed and then the rules should not work.
It is important that the rule with the exception of the processing of static images also work.
Here is the complete .htaccess code:

RewriteEngine on
RewriteBase /

#/img/40x40/images/article/631384704403-5354074831.jpeg
RewriteRule ^img/(\d+)x(\d+)/(.+)/?$ img?w=$1&h=$2&src=$3 [L,R=302]

#Excluding images
RewriteRule .*\.(jpg|gif|png|svg|css|js|kml|fb2|ico|html|xml|txt)$ - [L]

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ [NC,L]
RewriteRule ^.*$ index.php [NC,L]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg Krasnov, 2014-07-07
@OKrasnov

According to your rules, the conversion is successful for me with both [L,R=302] and [L] .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question