Unchecked runtime.lastError: The message port closed before a response was received
What it means: This is a Chrome/Edge browser extension error, NOT your code. Some browser extension tried to communicate with the page and failed.
Solution: Ignore it - it's harmless and doesn't affect your app.
api.php/api/seo-analysis/analyze:1 Failed to load resource:
the server responded with a status of 404 (Not Found)
What it means: The API router couldn't find the /api/seo-analysis/analyze endpoint.
Root cause: The router was receiving URLs like:
/rankmath/webapp/api.php/api/seo-analysis/analyze
But it wasn't properly stripping /api.php from the path, so it was looking for:
/api.php/api/seo-analysis/analyze ❌ WRONG
Instead of:
/api/seo-analysis/analyze ✅ CORRECT
Before:
$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$basePath = '/rankmath/webapp';
if (strpos($path, $basePath) === 0) {
$path = substr($path, strlen($basePath));
}
// Path still had /api.php in it ❌After:
$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
// Remove /rankmath/webapp
$basePath = '/rankmath/webapp';
if (strpos($path, $basePath) === 0) {
$path = substr($path, strlen($basePath));
}
// Remove /api.php (NEW!)
if (strpos($path, '/api.php') === 0) {
$path = substr($path, strlen('/api.php'));
}
// Ensure path starts with /
if (empty($path) || $path[0] !== '/') {
$path = '/' . $path;
}Before:
$url = $_POST['url'] ?? ''; // Doesn't work with JSONAfter:
$input = json_decode(file_get_contents('php://input'), true);
$url = $input['url'] ?? ''; // Now reads JSON properly-
Browser sends:
POST /rankmath/webapp/api.php/api/seo-analysis/analyze Body: {"url": "https://example.com", "is_competitor": false} -
Router receives:
REQUEST_URI: /rankmath/webapp/api.php/api/seo-analysis/analyze -
Router strips base paths:
Step 1: Remove /rankmath/webapp Result: /api.php/api/seo-analysis/analyze Step 2: Remove /api.php Result: /api/seo-analysis/analyze ✅ -
Router matches route:
POST /api/seo-analysis/analyze → SeoAnalysisController@analyze -
Controller reads JSON:
$input = json_decode(file_get_contents('php://input'), true); // Gets: ["url" => "https://example.com", "is_competitor" => false]
-
Returns success:
{ "success": true, "message": "Analysis complete", "data": { "score": 85, "results": {...} } }
http://localhost/rankmath/webapp/test-api.html
This test page lets you:
- ✓ Test the health endpoint
- ✓ Test dashboard stats
- ✓ Test SEO analysis with any URL
Health Check:
curl http://localhost/rankmath/webapp/api.php/api/healthDashboard Stats:
curl http://localhost/rankmath/webapp/api.php/api/dashboard/statsSEO Analysis:
curl -X POST http://localhost/rankmath/webapp/api.php/api/seo-analysis/analyze \
-H "Content-Type: application/json" \
-d '{"url":"https://example.com","is_competitor":false}'The original code worked in a root directory setup like:
/api.php/api/seo-analysis/analyze
But in your subdirectory setup:
/rankmath/webapp/api.php/api/seo-analysis/analyze
The router needed extra logic to strip both the subdirectory AND the api.php filename.
Your API routing now works correctly for:
- ✅ Subdirectory installations (/rankmath/webapp/)
- ✅ JSON POST requests
- ✅ All HTTP methods (GET, POST, PUT, DELETE)
- ✅ Dynamic route parameters ({id})
- ✅ Proper error responses
The webapp should now work perfectly!