简体   繁体   中英

htaccess - rewrite .php to .png in multiple subfolders

On my website I have a folder called /banners/ . This folder contains 3 subfolders, /small/, /medium/ and /big/ . All of the subfolders have an index.php file that require a parameter to work.

To make it a bit easier to understand:

/banners/ -> /small/ -> index.php?server=$id
             /medium/ -> index.php?server=$id
             /big/ -> index.php?server=$id

What i'm trying to do is i want to make /banners/small/index.php?server=$id (and the other 2 subfolders) to look like /banners/small/$id.png . Is it possible to rewrite the index pages to a .png file with only 1 htaccess file which is located in the /banners/ folder?

You can put this code in your htaccess (assuming it is in /banners/ folder like you said)

RewriteEngine On
RewriteBase /banners/

RewriteRule ^(small|medium|big)/(.+?)\.png$ $1/index.php?server=$2 [L]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM