Alter htaccess for $_GET utm_medium from dlvr.it - php

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.”

Related

mod rewrite with fixed string between two dynamics

I've got an URL like this:
filter.php?gender=male&fid=1&sid=x
and I want to use mod_rewrite to rewrite it like this:
/Male/Apparel/Jackets
as an example...
I already tried the following but itonly puts the first var (male) to the query string and skips the second one (example: jackets)
RewriteRule ^([a-zA-Z]+)/Apparel/^([a-zA-Z]+) filter.php?gender=$1&fid=1&sid=$2
I also tried the following syntax without success:
RewriteRule ^([a-zA-Z]+)/Apparel/([a-zA-Z]+) filter.php?gender=$1&fid=1&sid=$2
What have I done wrong? Isn't it possible to put an exact string between two dynamic string or did I just use a wrong syntax?

Apache mod_rewrite: rewrite a path into a query string of an existing file

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

Use url instead of get [duplicate]

I want to know how I can pass parameters between pages through the URL without having to add variables eg:
mydomain.com/file.php?var1=val1&var2=val2&...varN=valN
I want to use it as follows:
mydomain.com/file.php?val1-val2-...-valN
I also see in some website the URL is in the following format
mydomain.com/file/####
which redirects to another page without changing the URL as if this is the URL to the file.
You should use .htaccess
Here's an example:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^([0-9-_]+)/([a-zA-Z0-9-_]+)/?$ index.php?var1=$1&var2=$2 [NC,L]
This basically means that if the URL is formatted according to the regular expressions above (number - slash - alphanumeric,dashes or underscores) than the content should be displayed from index.php while passing the file two parameters called var1 and var2, var1 having the value of the number and the second having the value of what's after the first slash.
Example:
mysite.com/20/this_is_a_new_article/
Would actually mean
mysite.com?var1=20&var2=this_is_a_new_article
Of course, in your index.php file you can simply take the values using
$var1 = $_GET['var1'];
$var2 = $_GET['var2'];
Cheers!
Your third example is an example of how REST identifies a server side resource. What you are talking about here sounds very much like REST will do what you want. I would suggest starting here (http://en.wikipedia.org/wiki/Representational_State_Transfer#RESTful_web_services).

base64 encode is giving me strange results after using url rewrite

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.

PHP passing parameters via URL

I want to know how I can pass parameters between pages through the URL without having to add variables eg:
mydomain.com/file.php?var1=val1&var2=val2&...varN=valN
I want to use it as follows:
mydomain.com/file.php?val1-val2-...-valN
I also see in some website the URL is in the following format
mydomain.com/file/####
which redirects to another page without changing the URL as if this is the URL to the file.
You should use .htaccess
Here's an example:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^([0-9-_]+)/([a-zA-Z0-9-_]+)/?$ index.php?var1=$1&var2=$2 [NC,L]
This basically means that if the URL is formatted according to the regular expressions above (number - slash - alphanumeric,dashes or underscores) than the content should be displayed from index.php while passing the file two parameters called var1 and var2, var1 having the value of the number and the second having the value of what's after the first slash.
Example:
mysite.com/20/this_is_a_new_article/
Would actually mean
mysite.com?var1=20&var2=this_is_a_new_article
Of course, in your index.php file you can simply take the values using
$var1 = $_GET['var1'];
$var2 = $_GET['var2'];
Cheers!
Your third example is an example of how REST identifies a server side resource. What you are talking about here sounds very much like REST will do what you want. I would suggest starting here (http://en.wikipedia.org/wiki/Representational_State_Transfer#RESTful_web_services).

Categories