Skip to contentSkip to main navigation Skip to footer

How Can I Hide The Old Images Paths?

You can set from Hide My WP > Change Paths > WP Core Security > Hide WordPress Common Paths the extension files you want to hide on the old paths.

By default, the images are not included as it may affect the indexed Google images.

After you change the paths, it will take a while for Google and other search engines to index the new images URL.

If you still want to hide the old images, add this line in wp-config.php file

define('HMW_HIDE_OLD_IMAGES', true);

and you will see the images option in the Hide File Extentions list:

Select the Images and save the settings.

Redirect images from the old paths to the new paths

It is important not to have the same image on two different URLs on a website to avoid duplicate content issues and to maintain good search engine optimization (SEO) practices. When search engines like Google detect duplicate content, it can negatively impact the website’s visibility and rankings in search results.

  1. Set a new uploads path. Choose a directory name in Hide My WP > Change Paths > WP Core Security like “storage” where you want to store the uploaded images.
  1. Add the below code in the config file.

For Apache/Litespeed, locate the .htaccess file in the root directory of your website and add the following code at the beginning of the file:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{THE_REQUEST} /wp-content/uploads/[^\.]+(\.jpg|\.png|\.jpeg|\.webp|\.gif) [NC]
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-content/uploads/(.*)$ /storage/$2  [L,R=301]

For Nginx servers add this code before the Hide My WP Ghost include line in the Nginx config file:

  if ($request_uri ~* ^/wp-content/uploads/[^\.]+(\.jpg|\.png|\.jpeg|\.webp|\.gif)){
    rewrite ^/wp-content/uploads/(.*)$ /storage/$1 redirect;

This code utilizes mod_rewrite, a module that allows URL rewriting. It checks if the request is for an image file within the /wp-content/uploads/ directory and redirects it to the corresponding file in the /storage/ directory.

By implementing this solution, any requests for images in the old /wp-content/uploads/ directory will be redirected to the new /storage/ directory, preventing duplicate URLs for the same image.