I have a really strange problem
ok the problem is thus
let say I have this url
http://www.example.com/?file=WFS010C.part3.rar&url=http://www.fileserve.com/file/vEpByp3/WFS010C.part3.rar
If I do base64_encode($_GET['url'])
the results is this
aHR0cDovL3d3dy5maWxlc2VydmUuY29tL2ZpbGUvdkVwQnlwMy9XRlMwMTBDLnBhcnQzLnJhcg==
after applying this rewrite condition
RewriteEngine On
RewriteBase /
RewriteRule ^file-(.*)-(.*)\.html$ index.php?file=$1&url=$2
The url is like this
http://www.example.com/file-WFS010C.part3.rar-http://www.fileserve.com/file/vEpByp3/WFS010C.part3.rar.html
now if I do base64_encode($_GET['url'])
the results is this
aHR0cDovd3d3LmZpbGVzZXJ2ZS5jb20vZmlsZS92RXBCeXAzL1dGUzAxMEMucGFydDMucmFy
**Note that the value of $_GET['url'] is exactly the same in both cases if printed without encoding!!!!
how come same string giving different results just after using rewrite ?**
Does anyone know whats the problem
You can use base64_decode to see whether they are same.
In fact:
The first one is
http://www.fileserve.com/file/vEpByp3/WFS010C.part3.rar
And the second one is
http:/www.fileserve.com/file/vEpByp3/WFS010C.part3.rar
You can see, they are not same.
You are rewriting your URl so the part after the second - is stored in url parameter. So in second case you receive url = http://www.fileserve.com/file/vEpByp3/WFS010C.part3.rar.html. Just like you had before.
What you are encoding is marked with bold:
With first url
http://www.example.com/?file=WFS010C.part3.rar&url=http://www.fileserve.com/file/vEpByp3/WFS010C.part3.rar
With second URL you are rewriting it to
http://www.example.com/index.php?file=WFS010C.part3.rar&url=http://www.fileserve.com/file/vEpByp3/WFS010C.part3.rar
UPDATE your second base64_encoded URL is decoding to http:/www.fileserve.com/file/vEpByp3/WFS010C.part3.rar. Note single / after http. Are you sure you have no typos in second URL?
First you need to urlencode the 'url' parameter. I'm guessing the parameter does not get correctly parsed because of invalid characters like '/' in it.
Related
I am creating a simple redirect tool for myself in PHP. I'm going to store codes that map to their respective URLs in an associative array, and then redirect anybody who inputs this code to their URL.
I am using query strings to GET the input (the name of the variable and the value, which is the code), and I already know how to make the redirect part work with PHP. The issue is, I don't want my users to have to type in a question mark, the name of the variable, and then an equals sign. I would like for them to simply type in a path that will be converted into a query string, so that PHP can process the redirection.
I was wondering how I could turn a path (an arbitrary URL path) into a query string of an existing file. I was able to find the opposite task quite easily on Stack Overflow (.htaccess - Rewrite query string and redirect to directory) but I want to be able to pass any arbitrary URL path (that does not exist in the directory) into an existing file's query string. I found an example of what I wanted (URL rewrite for converting path to querystring), but it was for multiple query strings and in this case, I only need one. I don't think the last question I referenced was successfully answered either.
How can I redirect
https://www.example.com/r/blahblahblah
into
https://www.example.com/r/index.php?r=blahblahblah
using .htaccess, so that I can parse the query string in my PHP file?
Something like this:
RewriteRule ^(.*)$ index.php?r=$1 [NC,L,QSA]
On this URL:
example.com/r/blahblahblah
From index.php:
print_r($_GET);
Will return this:
Array ( [r] => blahblahblah )
(Edit to mention this assumes .htaccess is in the /r directory)
RewriteEngine On
RewriteRule ^r/([a-zA-Z0-9]+)$ /r/index.php?r=$1
Dlvr.it puts utm_source and utm_medium in the URLs it generates. I am trying to access those in my PHP code but the page cannot get its value. The two values of utm_medium I'm looking to track are twitter or Facebook.
Example url that doesn't work: example.com/page/id?utm_source=dlvrit&utm_medium=twitter
Example that DOES work: example.com/page.php?id=xxx&utm_medium=twitter
Any one have any idea why I cannot access it or any experience with using dlvr.it generated URLs?
What I have:
$source = $_GET['utm_medium'];
echo $source;
I am getting the error: Undefined index: utm_medium
EDIT: My htaccess is structured so the page is displayed as /page/xxx (xxx being an id number) so the parameters from dlvr.it are not active. How can I go about altering my htaccess to gain access to these parameters?
Add the flag [QSA] to your RewriteRule – stands for Query String Append, and will append the original query string to the address that you rewrite to internally.
http://httpd.apache.org/docs/2.2/rewrite/flags.html#flag_qsa:
“When the replacement URI contains a query string, the default behavior of RewriteRule is to discard the existing query string, and replace it with the newly generated one. Using the [QSA] flag causes the query strings to be combined.”
My variable with javascript looks like this:
var email = encodeURIComponent($('input[name=\'email\']').val())
email is clearly being encoded and is producing this when sent to server: email%2540yahoo.com
What function in PHP will decode this value properly?
I've tried using html_entity_decode
The correct url encoding for # is %40.
When a url, for example from an e-mail, with the encoded # character in it, is redirected using a rewrite rule, it will be rewritten as %2540 (the % is encoded as %25). If you keep rewriting / redirecting, you will replace % with %25 each time, ending up with %25252540 (or more 25, you get the picture).
For example clicking this:
http://example.org?email=info%40example.org
Will produce after a rewrite and redirect using a rewrite rule:
https://example.org?info%2540example.org
in the browser address bar, which does not correctly translate to info#example.org in php.
What function in PHP will decode this value properly?
You don't need to decode anything. $_GET["email"] and $_POST["email"] will work just fine. The encodeURIComponent function is used to properly url encode a url to avoid having invalid urls. If you have a valid url, PHP will successfully be able to read the parameters.
echo urldecode(urldecode('email%2540yahoo.com')); // email#yahoo.com
Try urldecode(<value_to_decode_here>);
I have two URLs.
This one works: equipo.php?equipo=sk+gaming&page=2&ipp=24
This one does not: equipo/sk+gaming.html?page=2&ipp=24
equipo/sk+gaming.html does the same thing as equipo.php?equipo=sk+gaming, as it should.
My problem is that when using equipo/sk+gaming.html?page=2&ipp=24, the page parameter isn't there.
Why am I not getting the page parameter and how can I fix it?
If you're using Apache's mod_rewrite, the RewriteRule probably doesn't have the QSA flag.
i have written a code in .htaccess
RewriteEngine on
RewriteRule ^category-search/(.*)$ category-search.php?cat_id=$1
and my current URL is
www.mydomain.com/category-search/=NA==
Last values (=NA==) is encoded in base64_encode.
But when i m trying to fetch this values in php like...
$val=mysql_real_escape_string(base64_decode($_REQUEST['cat_id']));
I am getting $val equal to nothing. What is error behind this ?
When i was not rewrite in htaccess this was working well.
=NA== is not a valid base64-encoded string (wrong length and invalid character at the beginning). Did you mean NA64==? That decodes to 4.
In case of =NA==, base64_decode() would return false, which outputs as empty string.
shouldn't you be looking at $_REQUEST['cat_id'] instead of $_REQUEST['sub_cat_id'] as that is what you have called the request parameter in the .htaccess file...