【问题标题】: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,然后把这段代码放到你.htaccessDOCUMENT_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
    

    【讨论】:

      猜你喜欢
      • 2020-08-23
      • 2015-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-05
      • 1970-01-01
      • 2012-02-22
      相关资源
      最近更新 更多