Remove subdirectories with htaccess

Asked

Viewed 420 times

3

1 answer

1


Assuming that the mod_rewrite is enabled you can do the following in your . htaccess:

RewriteEngine  on
RewriteBase /
RewriteRule ^lojanova/(.+)$ $1 [R=301,L]
RewriteRule ^lojanova(/)?$ / [R=301,L]

This will generate an http redirect 301 permanently powered from any URL "/lojanova/[something]" to "/[something]" or from "/lojanova" to "/".

  • Strange, it still didn’t work. I need to have the old directory in question?

  • I end up getting 404 saying that the page does not exist. In fact, it no longer exists. However, I would like to tell the request that it has been moved to another address.

  • @Mateusprado you don’t need to have the old directory and these rewrite rules will exactly tell the request that "/lojanova/algo.html" has been moved to "/algo.html" and "/lojanova/categoria/product1.html" for "/category/product1.html" or any other variation. Did you check if mod_rewrite is enabled in your apache? post more details than you did.

  • Thanks for the quick Brunorb response. I checked with the hosting and they confirmed that mod_rewrite is active. As it is a shared hosting I do not have sudo access to make such a check. However, I created the htaccess file by copying and pasting what you recommended. I will take a server of mine and perform the tests to see if I have a different result and put here.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.