How to redirect url to parent directory with rewriting urls

I need to make redirects from a subdirectory to the parent directory.

In other words, I need to redirect everything that matches

http://exemple.com/portfolio/product1 

to:

 http://exemple.com/product1 

Is there a way to do this with a REWRITE URL?

thanks

+2
source share
2 answers

Include mod_rewrite and .htaccess through httpd.conf , and then put this code in .htaccess in the DOCUMENT_ROOT directory:

 Options +FollowSymLinks -MultiViews # Turn mod_rewrite on RewriteEngine On RewriteBase / RewriteRule ^portfolio/(.*)$ /$1 [L,R=301,NC] 
+3
source

You want to put this in .htaccess inside the directory you want to redo

 RewriteEngine On RewriteCond %{REQUEST_URI} !^/parent RewriteRule ^(.*)?$ http://%{HTTP_HOST}/parent 
+1
source

Source: https://habr.com/ru/post/1205202/


All Articles