将不存在的URL重定向到根目录

问题描述:

我已将网站从www.site.com/shop/子文件夹移至根目录.现在," shop "文件夹已不存在,我想将仍然要访问site.com/shop/whateverhtml的用户重定向到site.com/whateverhtml 我尝试了不同的重写规则,但是没有运气.

I have moved my site from www.site.com/shop/ subfolder to root. Now the "shop" folder doesn't exist anymore and I would like to redirect people who still go to site.com/shop/whateverhtml to site.com/whateverhtml I have tried different Rewrite rules but with no luck.

RewriteEngine on
RewriteRule %{REQUEST_URI} ^/shop/.*
RewriteRule shop/(.*)$ /$1 [R=301,L]

或类似的

RedirectMatch 301 ^/shop/$ http://site.com/

谢谢.

RewriteCond %{REQUEST_URI} ^/shop(/.*)?$
RewriteRule ^(.*)$ %1 [R=301,L]

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