skip to Main Content

My server to generating duplicate contenct on my php files.

For example, it generates fake pages like this:
https://westsidelosangeles.com/surfing-zuma-beach-malibu.php/best-parks-los-angeles.php

This is actually 2 pages served on top of one another by my server.

https://westsidelosangeles.com/surfing-zuma-beach-malibu.php
https://westsidelosangeles.com/best-parks-los-angeles.php

Should I make my links Absolute?

Should I add this code to my include? Where would I add it?

if (!empty($_SERVER['PATH_INFO'])) {
   header("HTTP/1.0 404 Not Found");
   die("nothing here"); 
}

I am hoping to find a way to stop my server from generating hundereds of fake pages like the link I provided above.

2

Answers


  1. Chosen as BEST ANSWER

    Thank you. I added to code snippet below to my navigation.php include file at the beginning, and it did not work.

    <body>
            <?php 
    if (!empty($_SERVER['PATH_INFO'])) {
       header("HTTP/1.0 404 Not Found");
       die("nothing here"); 
    } 
        ?>
    </body>
    

    My server is IONOS. I am not sure if it is APACHE

    Is the code snippet you gave me for the .htaccess ??


  2. You can definitely use the PHP code snippet you provided to check for and block unwanted PATH_INFO data. This will help prevent your server from serving content when additional path is appended to PHP file URLs.

    You can also put it in your comman include file write in the start of your script This way, you ensure that the check is made before any content is processed or output.

    Also if you are using Apache you can use .htaccess to stop such URLs

    you can do something like

    RewriteEngine On
    # Redirect or block URLs with PATH_INFO
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} ^(.+).php/(.+)$ [NC]
    RewriteRule . - [R=404,L]
    

    This rule checks if the request is for a non-existing directory or file that ends with .php/ followed by more characters, it responds with a 404 status code

    i guess any of the approach should solve your issue make sure to test it well after implementation.

    Hope it helps.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search