Is there a way in PHP to know if the current script (page) came from an apache 301 redirect?
Additional details to set the stage for this question:
We just completed a website merge, retiring one web site and sending it's traffic to a similar sister website which included 100s of individual 301 redirects for products, categories. We would like to track transactions that originated from the retired website URLs vs those originating from the current URL. Basically, as an order completed, we want to know which URL it had originated from, redirected from the old vs direct traffic from the new.
Currently the 301 redirects are performed via a separate file included in the httpd.conf file. This separate file contains 100s of "Redirect 301 /source /destination" directives.
My plan was to have PHP sniff out these redirects, store the original URL domain as a session variable, then access that session variable at order completion in order to connect it to that original domain.
For this to work, the landing page script would need to know if it is the result of a redirect. Which leads to the question: Is there a way in PHP to know if the current script (page) came from an Apache 301 redirect?
Thanks in advance for your help.
Related
To clarify, I am not after the url of my server, or the scripts running on my server. What I have is a game program that I rent out to other sites who wish to use it for traffic building. The game runs on my server so I can take care of any administration or programming issues. How I normally handle this is they create a folder with the same name as on my server, and use a .htaccess in that folder to redirect. The result is the game runs apparently from their site (the URI is their domain), but it actually is running on my server.
Now, one of my newer games, a customer wishes to have a 3 month exclusive right to run it from their site. Since their site and my site are not on the same server, I cant use sessions to track if they visited the customers site first before accessing the game.
What I am wanting is to use php to check what the original URI was before redirecting. THat is.. the URI the end user sees in their browser.
Any assistance will be grateful. Thanks
You can use in PHP the variable $_SERVER['HTTP_ORIGIN'] which contain origin domain of the HTTP request.
I'm using htaccess to rewrite and redirect www.mysite.com/index.php?id=# to friendly urls like www.mysite.com/news. So all news-articles will be written as www.mysite.com/news/article1, etc.
Now I'm blocking off all directories on my server that it doesn't need to index with robots.txt. Since I'm using a cms these are directories like /core, /managers, /connectors, etc. But since the www.mysite.com/news directory doesn't actually exist, but is rewritten with htaccess, will blocking off all the directories like /core, etc. still allow a crawler to index my website?
So basically what I want to know is: does a crawler see my website urls as they are after they're rewritten? Or does it still need access to the other directories of my cms, like /core to be able to index my pages?
No, the rewritten URL is an internal mapping process only. It is only used by your web server to determine how to treat the user-friendly URL it receives.
The same way the URL remains unchanged in a browser address bar, the process is invisible to the client, be it a web browser or a bot.
URL Rewriting is not to be confused with Redirection. In the latter case, a client request receives a "301 Redirect" response containing the URL where the actual resource resides. This results in a second request from the client to the redirected URL. Then by definition the client will be aware of this process.
First
Let say that i have www.domain.com that are client site and user login and do all the thing that he want (site is main and he use POST method for login adn other things and HEADER redirect if login are success)
But i not want user to see original www.domain.com i want when they enter www.name.com/dashboard.php to see content from www.domain.com/dashboard.php but him URL bar to show www.name.com/dashboard.php ..and like this all other page that can have original www.domain.com
I found this site:
http://www.htmlremix.com/css/permanent-url-masking-for-mirroring-website-using-php-and-htaccess
Adn use script but when are entered user login detail noting happen!! Just home page reload.
I try everything that i think may be cause problem and not found how to solv it .. So please help me!!
Thanks Allot
P.S. If have some more good way that can i use also will help me!
that cant be achieve with a htaccess file.
You need different things.
possible solution could be:
apache mod proxy so you could proxy everything through that url.
the other way could be a php written some kind of proxy. Working with curl or and remote configured fopen.
But be careful to also send the post data and the cookies, otherwise the user session could not be handled if its cookie based.
If both domains are on the same server you could easily set this up with a vhost configuration in apache/nginx what ever you are using.
E.g. I have two domains:
http://www.computer.com
http://www.computers.com
http://www.computer.com is main website and http://www.computers.com is just dummy that will redirect to main website (http://www.computer.com).
So my goal with pure PHP is to detect that user comes from http://www.computers.com rather than google or other website or directly typing url without using refer since it can be disabled.
Both sites are on same hosting, but I cannot access file system of one site from another. And $_SESSION is or $_COOKIE are domain specific variables too.
You could set your redirect script to push to www.computer.com?ref=sister or some similar URL, then log accordingly and, if desired, redirect back to home to keep it transparent to the user.
Are you asking for an htaccess example though? Or just ideas on how to do it?
You say pure php in your computers.com index file:
<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.computer.com?ref=sister");
?>
Your best bet is to to address your issues on multiple levels. First you should point DNS for www.computers.com to point at the IP address for www.computer.com. Now both of your requests are being served by the same server or cluster of servers(if behind a load balancer).
Second, if you actually want to rewrite the URL to utilize a single domain (to consolidate your cookies, sessions, etc.), then you could use webserver redirection (i.e. mod_rewrite for Apache) to redirect all the requests to the final domain.
Finally, in that rewrite, you should send 301 codes on rewrite to make sure that spiders and such know that this is a permanent redirection.
Basically, I'd like it to work like this:
1) if user clicks the download link on my site then download starts as expected
2) if user clicks the download link on third-party site then (s)he is redirected to my site (where download starts automatically shortly thereafter)
I don't want to serve files with PHP, as this is expensive. Maybe some cookie checking on NGINX's part is possible? Say, all paths
site.name/files/app_id/file_name.zip
should be redirected to
site.name/download/app_id
if cookie is not present.
Would appreciate any ideas/examples on how to do this.
Do you have access to mod_rewrite? You can redirect the users based on the domain in his referrer. Try this.
don't forget that some users might not send referrers and are therefore not be able to download from your site at all.