Solved

Mod Rewrite - Pages load fine, but facebook and google think 404

Posted on 2011-10-01
2
482 Views
Last Modified: 2012-05-12
I need someone with experience using mod_rewrite.

I have a connect script running in sub director /health/ (you can see the connect script below).

The connect script is in file index.php. It populates data from remote DB with urls that appear like so:

/health/index.php?resource=/assets/heart

I would like them to appear like this:

/health/assets/heart

When I changed the request handler from:

"request_handler_uri=" . urlencode("/index.php?resource="),

To

"request_handler_uri=" . urlencode("/health"),

The url structure appears corectly, yet I get 404.

So I changed the htaccess to:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /health/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule index.php(.*)$ index.php?resource=/$1 [QSA]
RewriteRule ^(.*)$ index.php?resource=/$1 [QSA]
</IfModule>

So the page loads fine, I can see it etc, but not google or facebook etc. When I test using
developers.facebook.com/tools/debug/og/object

Facebook returns error "the server responded 404 error".

Any ideas?

<?php

$api_uri = "http://web.contentsource.com/blahblah";

$parameters = array(
	"apikey"				=> "5551212",
	"format"				=> "atom",
	"links"					=> "resource-path",
	"styles"				=> "enhanced",
	"content_only"			=> "false",
	"prettyprint"			=> "false",
	"request_handler_uri"	=> "http://www.mydomain.com/health/"
);

if (array_key_exists("resource", $_GET))
{
	$resource = urlencode($_GET['resource']);
}

if (!isset($resource) || $resource == "/")
{
	//default content uri goes here	
	$resource = "/assets/~default";
}

$request_uri = $api_uri . $resource . "?" . http_build_query($parameters);

$curl = curl_init($request_uri);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 1);
curl_setopt($curl, CURLOPT_TIMEOUT, 5);
$response = curl_exec($curl);
    
header("Content-type: text/html; charset=utf-8");


/*$pattern='#<entry(.*)\<content type=\"xhtml\">#si';
preg_match($pattern,$response,$piece);*/



$pattern='#\<id>(.*)\<\/id>#si';
preg_match($pattern,$response,$piece);

$pattern='#\<summary type=\"text\">(.*)\<\/summary>#si';
preg_match($pattern,$response,$description);

$pattern='#\<author>(.*)\<\/author>#si';
preg_match($pattern,$response,$author);

$pattern='#\<updated>(.*)\<\/updated>#si';
preg_match($pattern,$response,$updated);


$response=str_replace($piece[0],"",$response);
$response=str_replace($description[0],"",$response);
$response=str_replace($author[0],"",$response);
$response=str_replace($updated[0],"",$response);


$pattern='#\<title>(.*)\<\/title>#si';
preg_match($pattern,$response,$title);
$title=$title[0];

$pattern='#\<summary type=\"text\">(.*)\<\/summary>#si';
preg_match($pattern,$response,$description);
$description='<meta name="description" content=\''.$description[1].'\'>';

$pattern='#<link(.*)/>#U';
preg_match_all($pattern,$piece[0],$links);
$links=$links[0];

$new_content = strip_tags($response);
$new_content = eregi_replace("<head[^>]*>.*</head>"," ",$new_content);
$new_content = eregi_replace("<script[^>]*>.*</script>"," ",$new_content);
$new_content = eregi_replace("<style[^>]*>.*</style>"," ",$new_content);
$new_content = eregi_replace("<[^>]*>"," ",$new_content);
$new_content = eregi_replace("&nbsp;","",$new_content);

$resource = urldecode($resource);
$theurl = "http://www.mydomain.com/health" . $resource;
?>

Open in new window

0
Comment
Question by:cptnem0
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 15

Accepted Solution

by:
babuno5 earned 500 total points
ID: 36898258
your code seems to be fine

What can be checked now is when you make request from facebook check your apache access log and see for what url you are getting 404.



0
 

Author Closing Comment

by:cptnem0
ID: 37065093
Checking apache logs did lead to finding the problem. There was a { somewhere causing an error.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question