logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Coding & Scripting Corner View previous topic :: View next topic
Reply to topic   Topic: Canonical balise and url rewriting
Author
bagu



Joined: 06 Jan 2011
Posts: 187
Location: France

PostPosted: Sun 03 Dec '23 18:54    Post subject: Canonical balise and url rewriting Reply with quote

Hello,

Google tell me i have a problem with my url.
I use url rewriting to get https://www.bagu.fr/outils.html from https://www.bagu.fr/index.php?page=outils

I use this <link rel="canonical" href="https://www.bagu.fr/outlis.html" /> in my web page.

Do you know how to correct this "error" from google validation ?
Thanks
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7294
Location: Germany, Next to Hamburg

PostPosted: Sun 03 Dec '23 21:44    Post subject: Reply with quote

in the index.php check for the query in the URL and redirect it with a 301 header.
Back to top
bagu



Joined: 06 Jan 2011
Posts: 187
Location: France

PostPosted: Tue 05 Dec '23 0:35    Post subject: Reply with quote

Replacing :

Code:
RewriteBase /
RewriteRule ^([a-z]+).html index.php?page=$1 [L,PT,QSA]


by

Code:
RewriteBase /
RewriteRule ^([a-z]+).html index.php?page=$1 [L,R=301]


Would work ?
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7294
Location: Germany, Next to Hamburg

PostPosted: Tue 05 Dec '23 12:37    Post subject: Reply with quote

This is not what I meant. Leave the URL rewriting as it is.

Code:

<?php
$parsed_url = parse_url(filter_input(INPUT_SERVER, 'REQUEST_URI', FILTER_SANITIZE_URL));
if(str_contains($parsed_url['path'],'/index.php')){
   header('Location: ' . filter_input(INPUT_GET, 'page', FILTER_SANITIZE_URL) .'.html' , true, 301);
   die();
}
?>
Back to top
bagu



Joined: 06 Jan 2011
Posts: 187
Location: France

PostPosted: Tue 12 Dec '23 17:53    Post subject: Reply with quote

Oh, ok... I misunderstood.
It work very well, thanks Wink
Back to top


Reply to topic   Topic: Canonical balise and url rewriting View previous topic :: View next topic
Post new topic   Forum Index -> Coding & Scripting Corner