How to redirect url to parent directory with url rewriting

纵然是瞬间 提交于 2019-12-12 13:22:10

问题


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


来源:https://stackoverflow.com/questions/18468787/how-to-redirect-url-to-parent-directory-with-url-rewriting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!