duanlianyun0462 2018-04-13 22:58
浏览 169

将整个子目录重定向到根目录

So I am trying to clean up my search engine redirect errors. I had some old development sites that got indexed that I want to redirect to the main site.

Basically I want everything in the /dev/ folder to go to https://myfakewebsite.com/

I added this to .htaccess file in the /dev/ directory:

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(.*)$ /$1 [R=301,L]

I tried this but it doesn't quite work, it does take out the /dev/ but it keeps the rest of the link there.

For example: https://myfakewebsite.com/dev/index.php?route=product/category&path=122

redirects to: https://myfakewebsite.com/index.php?route=product/category&path=122

I want it to redirect to: https://myfakewebsite.com/ (removing the /index.php?route=product/category&path=122 part).

Is there a way to do this with .htaccess?

  • 写回答

3条回答 默认 最新

  • dongzi9196 2018-04-13 23:31
    关注

    You might want to achieve this kind of "trivial" redirect with the RedirectMatch directive from mod_alias, instead of doing this with mod_rewrite.

    RedirectMatch 301 "/dev/(.*)" "/$1"
    

    See documentation at https://httpd.apache.org/docs/2.4/mod/mod_alias.html.

    评论

报告相同问题?