Search code examples
php.htaccessmod-rewriteurl-rewriting

.htaccess Rewrite an url with arguments in gif url


after some research i am still not able to find a solution which work fine for me.

now i have an url like this :

--> http://www.localhost.com/images/values-lock/countdown-timer.php?time=201504051144

and i want to rewrite and make appear this url in the browser with the possibility to get the time param above :

--> http://www.localhost.com/201504051144/timer.gif

actually my last try look like this :

--- .htaccess ---

  RewriteEngine On
   RewriteBase /images/values-locked/
   RewriteRule ^([a-zA-Z])?([a-zA-Z])=([0-9]+)$ $1/timer.gif [QSA]

i am not use to rewrite url way yet but still looking the doc and topic around.

thanks for your consideration.


Solution

  • You can use this code in your DOCUMENT_ROOT/.htaccess file:

    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{THE_REQUEST} /images/values-lock/countdown-timer\.php\?time=([^\s&]+) [NC]
    RewriteRule ^ %1/timer.gif? [R=302,L,NE]
    
    RewriteRule ^([^/]+)/timer\.gif$ images/values-lock/countdown-timer.php?time=$1 [L,QSA,NC]