【问题标题】:How to redirect url to parent directory with url rewriting如何通过 url 重写将 url 重定向到父目录
【发布时间】:2013-08-30 09:33:42
【问题描述】:
我需要从子目录重定向到父目录。
换句话说,我必须重定向任何匹配的东西
http://exemple.com/portfolio/product1
到:
http://exemple.com/product1
有没有办法用 URL REWRITE 做到这一点?
谢谢
【问题讨论】:
标签:
php
apache
.htaccess
mod-rewrite
url-rewriting
【解决方案1】:
通过httpd.conf启用mod_rewrite和.htaccess,然后把这段代码放到你.htaccess的DOCUMENT_ROOT目录下:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^portfolio/(.*)$ /$1 [L,R=301,NC]
【解决方案2】:
你想把它放到你想要重定向的目录中的 .htaccess 中
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/parent
RewriteRule ^(.*)?$ http://%{HTTP_HOST}/parent