我已经看过了,但找不到任何有效的东西。我有一个旧网站,我们已更新。他们将所有内容都放在根目录下名为 site 的文件夹下。现在,所有添加此书签的客户,无论文件夹站点(子文件夹、文件)之后是什么,我都希望将他们重定向到新站点的主页,而不是在我们的新 WordPress 安装中找不到的页面。任何帮助表示赞赏。
旧网址:http://www.oldsite.com/site/....
到新网址http://www.newsite.com
我已经尝试过了,没有效果
Rewrite Rule ^site/(.*)$ http://www.newsite.com
谢谢。
最佳答案
尝试:
RewriteEngine On
RewriteCond %{HTTP_HOST} oldsite.com$ [NC]
RewriteRule ^site/(.*)$ http://www.newsite.com/$1 [R=301,L]
这会将 http://www.oldsite.com/site/some-page.html
重定向到 http://www.newsite.com/some-page.html
(URI /site/之后的匹配位在 301 重定向中保留),但如果您想将/site/的所有内容重定向到 newsite 的索引根,请替换RewriteRule 中的目标为 http://www.newsite.com/
(删除 $1 位)。
编辑:
I actually write it wrong above. It is actually the same domain name. The question should read old URL mysite.com/site.... everything under this folder to just redirect to mysite.com
那么你想要的是:
RewriteEngine On
RewriteRule ^site/(.*)$ /$1 [R=301,L]
或者使用 mod_alias:
RedirectMatch 301 ^/site/(.*)$ /$1
关于.htaccess - htaccess 文件夹下所有内容的 URL 重写规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9894621/