• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 492
  • Last Modified:

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

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:


I would like them to appear like this:


When I changed the request handler from:

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


"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]

So the page loads fine, I can see it etc, but not google or facebook etc. When I test using

Facebook returns error "the server responded 404 error".

Any ideas?


$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';


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





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


$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

1 Solution
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.

cptnem0Author Commented:
Checking apache logs did lead to finding the problem. There was a { somewhere causing an error.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now