So.. I don't really know what goes wrong here. Therefore, it's probably bit of a vague question.
I wanted to improve my website's SEO. The final improvement that I want to realize are better URL's. (To my Surprise) it worked quite well! But while using Google's Search Console, Google (and others like: httpstatus.io) say that they can't fetch any of the pages affected by these new lines of codes. I guess it has something to do with the http status code... That's what I don't understand. Why?
I want to redirect requests like this:
http://ift.tt/2blDMlW -> http://ift.tt/2bjeM1K
(While the URL does not change of course.)
This is only required in the main directory.
So I started to Google the problem and used my own (very basic) knowledge, and this is de code I placed in the .htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^XXX\.XXX\.XXX\.XXX
RewriteRule (.*) http://ift.tt/1tdRfEE [R=301,L]
RewriteCond %{HTTP_HOST} !^www.example.net$ [NC]
RewriteRule ^(.*)$ http://ift.tt/1tdRfEE [L,R=301]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{SERVER_NAME}/$1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]*)(?!/.*)$ /index.php [L]
This is what I added to the index.php file:
<?php
function get_requested_page(){
$requested_uri = $_SERVER['REQUEST_URI'];
$requested_page = $requested_uri;
$requested_page = explode("/", $requested_page);
return($requested_page);
}
$requested_path_array = get_requested_page();
$i = 0;
foreach($requested_path_array as $part){
if($i !== 0){
$path .= "/" . $part;
}
$i++;
}
if (strpos($path, '?') !== false) {
$PathParameters = substr($path, strpos($path, "?"));
$arr = explode("?", $path, 2);
$path = $arr[0];
}
$path .= ".php";
if($path == "/.php"){
$path = "/home.php";
}
$filePath = $_SERVER['DOCUMENT_ROOT'] . $path;
$ErrorFilePath = $_SERVER['DOCUMENT_ROOT'] . "/404.shtml";
if(file_exists($filePath)){
header("HTTP/1.1 200 OK");
require $filePath;
} else {
//echo("https://$_SERVER[HTTP_HOST]" . $path);
//echo("<h1>404 ERROR - Page not found</h1>");
//die("<p>This page does not exist (anymore), or is moved.</p>");
header('HTTP/1.0 404 Not Found');
include $ErrorFilePath;
}
?>
Thnx for looking in to this. And sorry if I made some bad mistakes in my code and/or in this post. English is not my native language :)
Aucun commentaire:
Enregistrer un commentaire