我有一个带有论坛的网站,这是我的 htaccess 文件中的当前重写规则:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.*/?forum/?(.*)$ /forum.php [L]
现在,正因为如此,我有谷歌索引的网址,如:
www.domain.com/abc/forum/rest-of-url
www.domain.com/defg/forum/rest-of-url
www.domain.com/something-else/forum/rest-of-url
并且所有链接都显示相同的页面,只能通过以下方式访问:
www.domain.com/forum/rest-of-url
在 domain/ 和 /forum/ 之间没有任何词(abc、defg 等)
基本上任何类似这个链接的东西:
www.domain.com/abc/forum/rest-of-url
应该是301重定向到:
www.domain.com/forum/rest-of-url
我尝试将重写规则更改为:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule /forum/?(.*)$ /forum.php [L]
但是后来我在谷歌网站管理员工具中为所有以前索引的 URL 收到了很多 404 错误,所以我认为可以解决 301 重定向,但我还没有弄清楚如何避免陷入循环。
任何帮助表示赞赏。谢谢