htaccess redirect filename AND extension
Good Morning Folks,
Mission is to turn mysite/image开发者_如何学Cs/hotlinked.gif
into mysite/index.php?i=hotlinked.gif
.htaccess has been driving me all night, and it's time to get some coffee. Can you help me out?
RewriteEngine on
RewriteBase /
# Redirect direct links to index.php?i=var
RewriteRule ^(.+)\.(gif|jpg|png|bmp)$ http://mysite/index.php?i=$1 [L,NC,QSA]
returns mysite/index.php?i=hotlinked
no .gif
Also if I was searching in the wrong terms, could someone put it into htaccess jargon so I can properly post the fix on my blog?
Thanks and Happy Holidays
Replace $1
to $1.$2
. (or something, I don't know how to write write .htaccess, I helped myself replace function with regular expressions support in KWrite)
You are selecting two references in your regex. Where-ever you are using () you are making a new selection (that's over simplifying it. There are a number of examples where you would parenthesis without wanting to select what you are specifying) and are only passing the first one to the query. To pass the second one you need to add $2 to the query string.
For example change i=$1
to i=$1.$2
.
精彩评论