.htaccess rewrite imgname.jpg in image.php? img = imgname

I am trying to rewrite the urls like this:

domain.com/news/12/imgname.jpg 

to

 domain.com/image.php?img=12/imgname 

I use the following in my .htaccess file, but it does not seem to work:

 RewriteCond %{REQUEST_FILENAME} -f RewriteRule ^news/([0-9]+\/.*)\.jpg$ image.php?img=$1 [L] 

Can someone help me see what I did wrong?

+4
source share
2 answers

You should not avoid slash. Try the following:

 RewriteRule ^news/([0-9]+/.*)\.jpg$ /image.php?img=$1 [L] 
0
source

RewriteBase .htaccess file contain the corresponding RewriteBase directive? If not, add the following line before the rewrite rules:

 RewriteBase / 

You must also ensure that you have enabled the mod_rewrite engine with

 RewriteEngine On 
0
source

Source: https://habr.com/ru/post/1443825/


All Articles