通过 .htaccess 文件从"/foo/bar/..."重定向到仅"/..."



我的所有网站都在example.com/foo/bar/。我现在将其移至 example.com/ ,以提高可读性。如何通过 .htaccess 文件重定向所有仍转到example.com/foo/bar example.com/的访问者?
我也需要重定向所有子目录:例如从/foo/bar/baz重定向到/baz,从/foo/bar/baz/quax?id=5/baz/quax?id=5

试试这个:

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/foo/bar(.*)$
RewriteRule ^(.*) %1 [R=302,NC]

最新更新