【发布时间】:2018-07-21 05:34:29
【问题描述】:
长版(您可以跳到 TL;如果您愿意,可以跳到 DR):
我正在使用由其他人设置的 Wordpress 网站。该网站有多个页面,其中页面具有选项卡式内容,可通过 # 访问。例如:
www.example.com/services/category1/#tab-service1
www.example.com/services/category1/#tab-service2
www.example.com/services/category2/#tab-service1
www.example.com/services/category2/#tab-service2
www.example.com/services/category2/#tab-service3
现在,当搜索引擎索引时,它们只会索引www.example.com/services/category1/ 和www.example.com/services/category2/。这就产生了一个问题,我们不能让搜索引擎直接指向给定选项卡中的内容。我们想要的是让搜索引擎显示将用户直接带到(例如)www.example.com/services/category2/#tab-service3 的链接。
现在,我认为 google 无法自行索引此类基于 # 的内容。所以,我正在考虑使用 apache rewrites 来尝试解决这个问题。我只能访问 .htaccess 文件(从配置的角度来看)。
TL;DR
如何使用 apache 重定向将 www.example.com/services/category1/service3/ 重定向到 www.example.com/services/category1/#tab-service3(我可以访问 .htaccess 文件)?
这是我正在尝试的,但它不起作用:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/services/category1/([a-z0-9])/? [NC]
RewriteRule .* /services/category1#tab-%1 [R,NE,L]
有人还建议查看 pushState 服务器配置以解决此问题。我不确定如何使用 pushState。
更新:
我已将重写更新为以下内容,但仍然无法正常工作。它一直显示 Wordpress 的 404 页面
<IfModule mod_rewrite.c>
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /domainfolder/
RewriteCond %{REQUEST_URI} ^/services/category1/([a-z0-9]+)/?$ [NC]
RewriteRule ^/services/category1/([a-z0-9]+)/?$ /services/category1/#$1 [NE,R,L]
</IfModule>
【问题讨论】:
标签: wordpress apache .htaccess mod-rewrite url-rewriting