0

I'm generating a download link which I sent through email to download a pdf file. There are some parameters (base64 encoded) in the download link to verify the correct profile/user. I want to be the download link as follows:

www.example.com/download/ZW5jb2RlbXljb2Rl

The parameters are directly added after the subdirectory. I know it can be done with php GET as follows: www.example.com/download/index.php?base64=ZW5jb2RlbXljb2Rl

But in my opinion it is nicer to use the first URL. Except I have no idea how to accomplish this with php. My guess I have to make a rewrite in htaccess?

I found this thread: Rewriting a URL to a PHP parameter from inside a subdirectory

But I already have some htaccess rewrites (JOOMLA), and it is just for the only folder...

Thanks for your effort!

3
  • So you already know the answer is you need a rewrite rule. But you don't want to add another rewrite rule. So what can anyone possibly say to this? Commented Jun 10, 2015 at 23:35
  • 2
    You could use: www.example.com/download/index.php/ZW5jb2RlbXljb2Rl and the string would be available in $_SERVER['PATH_INFO']. Else, you would need another rewrite rule. Commented Jun 10, 2015 at 23:41
  • I used Panama Jack's answer, he suggested an URL rewrite. Thx for ur help! Commented Jun 15, 2015 at 6:49

2 Answers 2

2

You have no choice but to use rewrite for this That's what it's for.

But I already have some htaccess rewrites (JOOMLA), and it is just for the only folder..

This absolutely does not matter. Your Apache setup can contain as many rewrites as you need. I've seen 100's.

So you could just add these rules above your current Joomla rules and it should work.

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^download/(.+)/?$ /download/index.php?base64=$1 [L]

Otherwise you would have to do what Jonathan said and use index.php in your URL.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks for your answer.. I used this Rewrite and solved everything for me.
1

You can use echo basename($_SERVER['PHP_SELF']); to see your current page. You can explode the string after the last / using that:

$filename = explode('/', basename($_SERVER['PHP_SELF']));

That way if your link is www.example.com/download/ZW5jb2RlbXljb2Rl, then filename value will be "ZW5jb2RlbXljb2Rl".

I'm not sure if that's your question, but that should work depending on the usage.

1 Comment

You would need a rewrite rule or else that URL would just thrown a 404 error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.