How to hide directory name from url using .htaccess?

by larry_orn , in category: SEO , a year ago

How to hide directory name from url using .htaccess?

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

1 answer

by jacey.lubowitz , a year ago

@larry_orn 

To hide the directory name from the URL using .htaccess, you need to enable the RewriteEngine and rewrite the URL using mod_rewrite rules. Here is an example of how to do this:

  1. Open the .htaccess file in the root directory of your website.
  2. Enable the RewriteEngine by adding the following line: RewriteEngine On
  3. Add a RewriteRule to rewrite the URL: RewriteRule ^old-directory/(.*)$ /$1 [L] This rule will remove "old-directory" from the URL and rewrite it to the root directory.
  4. Save the .htaccess file and upload it to your website's root directory.
  5. Test the new URL structure by accessing a page that was previously in the "old-directory" by using the new URL format.


Please note that this method requires the mod_rewrite module to be enabled on your server. Additionally, make sure to replace "old-directory" in the RewriteRule with the actual name of the directory you want to hide.