You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CodeIgniter产品页面URL重复问题解决求助

解决CodeIgniter产品页面URL重复的问题

针对你遇到的产品页面存在两个重复URL(如https://www.bentleypartsusa.com/category/products_listing/138/和https://www.bentleypartsusa.com/category/products_listing/138/pg/)的问题,我们可以通过在.htaccess中添加301永久重定向规则来统一规范URL,让搜索引擎和用户都只指向同一个有效地址。

具体解决方案

我们需要将带/pg/后缀的URL重定向到不带该后缀的版本(若你更倾向保留带/pg/的版本,可反向调整规则)。把以下规则添加到你的.htaccess文件中,放在HTTPS和WWW强制跳转的规则之后、其他Redirect规则之前:

# 重定向带/pg/的产品URL到规范版本(去掉/pg/)
RewriteRule ^(category/products_listing/\d+)/pg/$ /$1/ [R=301,L]

如果你的网站其他页面也存在类似的/pg/后缀重复URL问题,可以使用更通用的规则(匹配所有以/pg/结尾的URL):

# 通用规则:重定向所有以/pg/结尾的URL到去掉/pg/的版本
RewriteRule ^(.*)/pg/$ /$1/ [R=301,L]

修改后的完整.htaccess示例

这里是整合后的完整配置,标注了新增的规则位置:

<IfModule mod_rewrite.c>
Options +FollowSymLinks -Indexes
Options -MultiViews
RewriteEngine on

# 强制HTTPS
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

# 强制WWW前缀
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.bentleypartsusa.com/$1 [L,R=301]

# --- 新增:解决URL重复的重定向规则 ---
RewriteRule ^(category/products_listing/\d+)/pg/$ /$1/ [R=301,L]
# --- 新增结束 ---

RewriteCond %{REQUEST_URI} ^/home$
RewriteRule ^(.*)$ https://%{HTTP_HOST}/ [R=301,L]

Redirect /home/car-red/feed/ https://www.bentleypartsusa.com/
Redirect /members/wishlist.html https://www.bentleypartsusa.com/
Redirect /pages/download_document/document/dumymy_pdf2.pdf https://www.bentleypartsusa.com/
Redirect /captcha/normal/15208659655aa692ad4f997 https://www.bentleypartsusa.com/
Redirect /captcha/normal/15653168405d4cd6e827d9e https://www.bentleypartsusa.com/
Redirect /captcha/normal/15286640755b1d900b1e51a https://www.bentleypartsusa.com/

# Keep people out of codeigniter directory and Git/Mercurial data
RedirectMatch 403 ^/(system\/cms\/cache|system\/codeigniter|\.git|\.hg).*$

# Send request via index.php (again, not if its a real file or folder)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
<IfModule mod_php5.c>
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_php5.c>
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
</IfModule>

注意事项

  1. 301重定向的缓存特性:浏览器会缓存301永久重定向,测试时建议使用隐私模式或清除浏览器缓存,确保看到真实的跳转效果。
  2. 反向规则调整:如果你更希望保留带/pg/的版本,只需调整规则方向:
    RewriteRule ^(category/products_listing/\d+)/$ /$1/pg/ [R=301,L]
    
  3. 效果验证:修改后可直接在浏览器访问两个URL,确认是否都跳转到你期望的单一地址。

内容的提问来源于stack exchange,提问作者Arun Kumar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 16:42:37