| 
 
 
 | 
| Keep Server Online 
 If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
 
 or
 
 
   
 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.
 |  | 
 | 
| | 
| | 
|  Topic: Canonical balise and url rewriting |  |  
| Author |  |  
| bagu 
 
  
 Joined: 06 Jan 2011
 Posts: 193
 Location: France
 
 | 
|  Posted: Sun 03 Dec '23 18:54    Post subject: Canonical balise and url rewriting |   |  
| 
 |  
| 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: 7442
 Location: EU, Germany, Next to Hamburg
 
 | 
|  Posted: Sun 03 Dec '23 21:44    Post subject: |   |  
| 
 |  
| 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: 193
 Location: France
 
 | 
|  Posted: Tue 05 Dec '23 0:35    Post subject: |   |  
| 
 |  
| 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: 7442
 Location: EU, Germany, Next to Hamburg
 
 | 
|  Posted: Tue 05 Dec '23 12:37    Post subject: |   |  
| 
 |  
| 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: 193
 Location: France
 
 | 
|  Posted: Tue 12 Dec '23 17:53    Post subject: |   |  
| 
 |  
| Oh, ok... I misunderstood. It work very well, thanks
  |  |  
| Back to top |  |  
 
 | 
 |  | 
 |  |