【问题标题】:How to .htaccess redirect file name to be url parameters on new domain?如何将 .htaccess 重定向文件名作为新域上的 url 参数?
【发布时间】:2015-11-28 01:16:13
【问题描述】:

我希望能够将subdomain.domain.com/426/long-tail-kw.html 等网址重定向到新域和differentdomain.com/goodname.php?id=long-tail-kw 等网址

另外,网址426 中的数字会经常变化,也可能是1 或不超过500 的任何数字

如何在 .htaccess 文件中执行此操作?

此外,重定向必须与此代码一起使用,该代码仅将来自 bing 的人发送到新网址。如果一个人只是输入 url,那么他不会被重定向,但是当他来自 bing 或任何指定的引用者时,他将被重定向。

到目前为止,我有这段代码用于我的旧网站,网址中有cat-x,但我不知道如何更改代码以仅使用网址中的数字而不是cat-x

 RewriteEngine On
 RewriteCond %{HTTP_REFERER} (bing)
 RewriteCond %{HTTP_HOST} ^(?:www\.)?server10\.olddomain\.com$ [NC]
 RewriteRule ^cat-\d+/(.+?)\.html$ http://newdomain.com/go.php?id=$1 [L,QSA,R=302]

【问题讨论】:

    标签: php apache .htaccess mod-rewrite redirect


    【解决方案1】:

    只需删除 cat- 部分:

     RewriteEngine On
     RewriteCond %{HTTP_REFERER} (bing)
     RewriteCond %{HTTP_HOST} ^(?:www\.)?server10\.olddomain\.com$ [NC]
     RewriteRule ^\d+/(.+?)\.html$ http://newdomain.com/go.php?id=$1 [L,QSA,R=302]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-09-07
      • 2014-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-04
      相关资源
      最近更新 更多