【问题标题】:mod_rewrite htaccess issuesmod_rewrite htaccess 问题
【发布时间】:2018-12-21 15:58:18
【问题描述】:

我有这样的网站:neotel2000.com:

  • 西班牙语:neotel2000.com
  • 英文:neotel2000.com/en/
  • 法语:neotel2000.com/fr/

好的。

我需要这个:

我希望与法语版本 (/fr/) 相关的每个可能部分,都将重定向 (301) 到根域 (neotel2000.com)。示例:

neotel2000.com/fr/whatever/ -----> neotel2000.com

虽然,有一些例外(即有 7 个与 /fr/ 相关的 url,其中 301 重定向不适用)我将向您展示这些 url 例外之一:

https://www.neotel2000.com/fr/standard-virtuel/

到目前为止,我已经在这里和其他论坛搜索了几十个 psot,但都没有运气。

这是我的 .htaccess 文件:

<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} !^GET\ ./https://www.neotel2000.com/fr/.*\ HTTP
RewriteCond %{THE_REQUEST} !^GET\ ./https://www.neotel2000.com/fr/standard-virtuel/.*\ HTTP
RewriteRule ^fr(.+)/ / [R=301,L]
</IfModule>

谢谢你的加载

【问题讨论】:

    标签: .htaccess redirect seo url-redirection


    【解决方案1】:

    你可以使用这条规则

    RewriteCond %{REQUEST_URI} !^/fr/(standard-virtuel|example2|example3)/ [NC]
    RewriteRule ^fr(/.*)?$ / [R=301,L]
    

    只需将example2example3、...替换为你想要的,每个都用|分隔

    或者,如果您更喜欢最长的版本(未压缩),其中每个条件都针对特定的 url

    RewriteCond %{REQUEST_URI} !^/fr/standard-virtuel/ [NC]
    RewriteCond %{REQUEST_URI} !^/fr/example2/ [NC]
    RewriteCond %{REQUEST_URI} !^/fr/example3/ [NC]
    RewriteRule ^fr(/.*)?$ / [R=301,L]
    

    【讨论】:

    • 它没有用。第一条规则和第二条规则都没有。还有其他建议吗?谢谢
    • 嗯,应该的。问题一定出在其他地方。确保启用mod_rewrite 并允许.htaccess 文件。另外,你还有其他规定吗?您使用 CMS 还是自定义网站?
    • 此外,它似乎在您的网站上按预期工作。刚刚尝试/fr/standard-virtuel/ 并且它可用,而/fr/whatever/ 正在被重定向到家。如果您没有看到相同的结果,请尝试清除浏览器缓存并重试
    • "确保 mod_rewrite 已启用"
    • 这里有我所有的规则: # Options +FollowSymlinks # RewriteEngine On RewriteBase / # RewriteCond %{REQUEST_URI} !^/fr/(standard-virtuel|@987654321 @ [NC] RewriteRule ^fr(/.*)?$ / [R=301,L]
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-10
    • 1970-01-01
    • 1970-01-01
    • 2010-12-02
    • 1970-01-01
    • 2016-07-14
    相关资源
    最近更新 更多