-1

I need to modify a generated file-download url to another with .htaccess

I need to make this URL:

http://example.com/download.php?file=Cool_Artist_-_Another_Cool_Song_id-1a2b3c4d5e6f7g8h_[www.mysite.com].mp3

Rewritten into this URL:

http://example.com/download/id-1a2b3c4d5e6f7g8h/Cool_Artist_-_Another_Cool_Song_[www.mysite.com]

Anyone can help me to figure it out?

halfer
  • 19,824
  • 17
  • 99
  • 186
Mikerobenics
  • 215
  • 6
  • 14
  • 1
    Hi Mikerobenics. Just so you know, we try to encourage posters to show some previous effort or prior research. The regex tag will often provide instant code-this-for-me answers, but the result of that is perhaps that OPs don't actually learn anything. If you can accompany your requirements with what you've tried, this is appreciated, and good attempts usually get upvotes. – halfer Feb 19 '15 at 09:41
  • With the information given it's not even clear whether your problem is that you misunderstand the basics of rewriting, or whether you simply can't come up with the correct rewrite rule syntax. Closing this as duplicate of the general reference until you can provide more details about your actual issue. – deceze Feb 19 '15 at 09:42
  • Hi deceze. I have read too many posts before asking the question. Unfortunately I can't find the exact answer that will suit my needs. I forgot to post what rewrite rule syntax I was tried. – Mikerobenics Feb 19 '15 at 14:51

1 Answers1

1

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

RewriteEngine On
RewriteBase /

RewriteRule ^download/([^/]+)/(.+?)_([^_]+)/?$ ?file=$2_$1_$3 [L,QSA,NC]
anubhava
  • 761,203
  • 64
  • 569
  • 643