How to redirect to upper directory with .htaccess?

by domenico.weimann , in category: SEO , a year ago

How to redirect to upper directory with .htaccess?

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

1 answer

Member

by jamison , a year 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.

Related Threads:

How to redirect to sitemap.php from htaccess?
How to block a directory with .htaccess?
How to hide directory name from url using .htaccess?
How to load .css file from parent directory with .htaccess rule?
How to redirect my site with .htaccess?
How to make a redirect with .htaccess?