How to redirect to upper directory with .htaccess?

by domenico.weimann , in category: SEO , 6 months ago

How to redirect to upper directory with .htaccess?

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

1 answer

Member

by jamison , 6 months ago

@domenico.weimann 

To redirect to the upper directory using .htaccess, you can use the following RewriteRule in your .htaccess file:

1
RewriteRule ^(.*)$ ../$1 [L,R=301]


Here's what this rule does:

  1. ^(.*)$ : This regex pattern matches any URL.
  2. ../$1 : This is the rewrite target, where "../" redirects to the upper directory, and $1 represents the captured URL pattern from the original URL.
  3. [L,R=301] : This flag specifies that the redirection is the last rule (L) and is performed with a 301 permanent redirection (R=301).


Make sure to place this rule in the .htaccess file located in the directory from where you want to redirect to the upper directory.