【问题标题】:issue with htaccess RewriteRulehtaccess RewriteRule 的问题
【发布时间】:2014-10-27 12:14:59
【问题描述】:

我正在为一个网站进行 SEO,并希望更正一些由 Google 网站管理员工具提供的“未找到”网址。

所以我开始处理 .htaccess 文件。

 http://www.chateau-de-beaugency.com/fr/index.php?id=12

应该是

 http://www.chateau-de-beaugency.com/fr/infos-legales-12

 http://www.chateau-de-beaugency.com/fr/index.php?id=42

应该是

 http://www.chateau-de-beaugency.com/fr/acces-presse-42

 http://www.chateau-de-beaugency.com/fr/index.php?id=11

应该是

 http://www.chateau-de-beaugency.com/fr/nous-contacter-11

 http://www.chateau-de-beaugency.com/fr/index.php?id=13

应该是

 http://www.chateau-de-beaugency.com/fr/plan-du-site-13

 http://www.chateau-de-beaugency.com/fr/fr/-6/les-services-35/index.php?id=13

应该是

 http://www.chateau-de-beaugency.com/fr/plan-du-site-13

 http://www.chateau-de-beaugency.com/fr/fr/-6/les-services-35/index.php?id=12

应该是

 http://www.chateau-de-beaugency.com/fr/infos-legales-12

 http://www.chateau-de-beaugency.com/fr/chateau-de-beaugency.com/fr/

应该是

 http://www.chateau-de-beaugency.com/fr/

感谢您的帮助

【问题讨论】:

    标签: regex apache .htaccess mod-rewrite redirect


    【解决方案1】:

    您可以在DOCUMENT_ROOT/.htaccess 文件中使用此代码:

    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{THE_REQUEST} \s/+/fr/fr/-6/les-services-35/index.php?id=12 [NC,OR]
    RewriteCond %{THE_REQUEST} \s/+fr/index\.php?id=12\s [NC]
    RewriteRule ^ /fr/infos-legales-12? [R=302,L]
    
    RewriteCond %{THE_REQUEST} \s/+(fr)/index\.php?id=(42)\s [NC]
    RewriteRule ^ /%1/acces-presse-%2? [R=302,L]
    
    RewriteCond %{THE_REQUEST} \s/+(fr)/index\.php?id=(11)\s [NC]
    RewriteRule ^ /%1/acces-presse-%2? [R=302,L]
    
    RewriteCond %{THE_REQUEST} \s/+(fr)/fr/-6/les-services-35/index.php?id=13\s [NC,OR]
    RewriteCond %{THE_REQUEST} \s/+(fr)/index\.php?id=13\s [NC]
    RewriteRule ^ /%1/plan-du-site-13? [R=302,L]
    
    RewriteCond %{THE_REQUEST} \s/+(fr)/chateau-de-beaugency.com/fr/\s [NC]
    RewriteRule ^ /%1/? [R=302,L]
    
    # internal forward from pretty URL to actual one
    RewriteRule ^(fr)/name-([^/]+)/?$ $1/index.php?id=$2 [L,QSA,NC]
    

    【讨论】:

    • 您好,感谢您的提示,但不幸的是它不起作用。看一看,我想要这个:chateau-de-beaugency.com/fr/index.php?id=12 去那里:chateau-de-beaugency.com/fr/infos-legales-12 我有这个消息:“找不到请求的 URL /fr/index.php 在这个服务器上找不到。” .htaccess 在我的虚拟主机的根目录上。是的,还有其他规则,如果您愿意,我可以发送原始文件?
    • 是的,它有所不同,实际上有 7 个不同的 url 谷歌网站管理员工具告诉我是 404。我猜它们是在我纠正我的 rewriteRules 之前被机器人索引的 url(它们运行良好),所以它索引了一些由于一开始我的规则配置错误,将重写的 url 与旧的 url 混合在一起。如果我清楚的话。
    • 我想我可以保留所有关于好 URL 的规则,并为 Google 工具检测到的少数 (7) 个坏 URL 添加一些硬编码的例外。不能用吗?
    • 我不能直接为 chateau-de-beaugency.com/fr/index.php?id=12 添加一个例外去 chateau-de-beaugency.com/fr/infos-legales- 12 ?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-02-09
    • 2014-07-04
    • 2016-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多