View Full Version : How do you extract part of a URL and use the leftover ...?

10-28-2012, 02:46 AM

Looking through my site stats via webalizer I noticed I get about 4,000 code 404 errors a month. I installed a script on the site that would email me and notify me what pages were being requested that would cause the 404 error code.

The majority of the error codes were being generated by this type of request:

The important thing I found out was that the URL after the

link=bit actually worked.

So what I am trying to do is to find a snippet of code that I can plug into the

external.htmlpage that would strip out

http://matrixfiles.com/external.html?link= (http://matrixfiles.com/external.html?link=http://www.bollyn.com/index.php?id=11077&print=1)leaving

http://www.bollyn.com/index.php?id=11077&print=1 (http://matrixfiles.com/external.html?link=http://www.bollyn.com/index.php?id=11077&print=1)to be passed to the browser.

I came across this question and example code

Question: How to trim a part of a string, and save it in a particular string in MySQL using PHP?
If a string has the value "REGISTER 11223344 here"
How can I cut "11223344" from the string?

One of the answers given was

$string = 'REGISTER 11223344 here'; $content = preg_replace('/REGISTER(.*)here/','',$string);Can I use this somehow to strip out the unwanted part of the URL? If so, how is the code to be written for my problem to be solved?

Not an expert on PHP so would much appreciate the help and so would 4,000 other users :)

10-28-2012, 04:49 AM
Sorry if I'm missing something, but isn't the value you want already assigned to the "link" variable? So if you're redirecting through that page immediately headers might work.

external.html (I assume you are parsing PHP in html files?)

<?php header (Location: $_GET['link']); ?>

.. Otherwise, if that page does other things that already send headers, you could put it in a meta redirect, or a Javascript redirect, but the value you want should be right there in $_GET['link'].

10-28-2012, 05:03 AM
external.html does not exist and I have no idea how it is being called with the rest of the link, so what I want to do is create one with the php code in it to take out the part of the url that makes the link bad.

If you are confused just try the link in full and then the bit after the
link=One thing that might be going on is that the bit after the link= part is a mirorred site that was ripped, with the site owners permission, by httrack and this site was then placed on my servers. There may be a problem with the way the site was ripped, but I would rather find a solution instead of either re-ripping the site or going over 5,000 pages and changing the code by hand.

10-29-2012, 10:28 PM
Is anyone able to help here?

10-30-2012, 01:16 AM
Is your domain "http://matrixfiles.com/", or "http://www.bollyn.com/"?

10-30-2012, 01:23 AM
My domain is http://matrixfiles.com

I want the bollyn.com website, and anything after bollyn.com, passed to the browser.

10-30-2012, 02:02 AM
So, can't you just create the page external.html and make it <?php header (Location: "\'". $_GET['link'] ."\'"); ?> or something? That should send anyone who views such a request on to the "link" part of the link, providing of course that all these requests are sent through external.html. Since you don't even know how that is being called the whole issue seems a bit trippy.

10-30-2012, 02:54 AM
I tried that and it didn't work.