Search code examples
.htaccessurlhttp-redirectmod-rewritehttp-status-code-301

redirect url from htaccess file


I'm trying to bulk redirect my site link like this,I need to remove home from every link and redirect it to root directory as shown below.

example.com/home/hello-world. 
example.com/home/tag/world.

to

example.com/hello-world
example.com/tag/world.

I'm using these code

RewriteEngine On
RewriteCond %{REQUEST_URI} (.+)/home(.*)$
RewriteRule ^ %1/ [R=301,L]

Solution

  • Considering that your htaccess rules file have more rules apart from your shown ones, which will take care of handling pages from backend(rewrite), if this is the case then please try following htaccess rules file.

    Please these rules at top of your htaccess rules file. Also make sure to clear your browser cache before testing your URLs.

    RewriteEngine ON
    RewriteBase /example.com/
    RewriteRule ^home/(.*)$ /$1 [R=301,L]