How to redirect url to parent directory with url r

2019-07-07 06:17发布

问题:

I need to make redirections from a sub-directory to the parent directory.

In other words I have to redirect anything matching

http://exemple.com/portfolio/product1

to :

http://exemple.com/product1

Is there any way to do that with URL REWRITE ?

Thanks

回答1:

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

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


回答2:

You want to put this into .htaccess inside the directory that you want to be redirrected

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