由于不值得在这里讨论的原因,Google 一直在为我的一个网站建立索引,其中 URL 中包含不必要的查询字符串。我想将我的 htaccess 文件修改为 301 将所有这些请求重定向到 URL,而无需查询字符串中不需要的部分,但保留查询字符串的任何其他部分,这些部分可能(或可能不是)作为地址的一部分确保保留其他功能。
例如,以下网址
http://example.com/product.php?query=12345
http://example.com/index.php?section=ABC123&query=56789
http://example.com/search.php?query=987654&term=keyword
Run Code Online (Sandbox Code Playgroud)
会成为
http://example.com/product.php
http://example.com/index.php?section=ABC123
http://example.com/search.php?term=keyword
Run Code Online (Sandbox Code Playgroud)
有效地剥离 'query=XXXXX' 加上 ? 或 &,但确保删除后保留其他查询并使用正确的语法(即,仅从第三个示例中删除 ?query=98765 是行不通的,因为它会将链接保留为 search.php&term=keyword 而不是 search .php?term=关键字)。
正在查看其他一些堆栈答案,发现了这个:
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} (.*)?&?query=[^&]+&?(.*)? [NC]
RewriteCond %{REQUEST_URI} /(.*)
RewriteRule .* %3?%1%2? [R=301,L]
Run Code Online (Sandbox Code Playgroud)
但这似乎不起作用,而且我对 htaccess 和正则表达式的了解还不足以找出原因。
预先感谢您的任何指点。
关于这个常见问题,我看到堆栈上有很多问题和潜在的答案.由于操作员输入错误或其他轻微变化,您有一个多年来可能吸引了多个重复记录的名称或公司或产品表.
我正在尝试创建一个后端管理工具来管理这个问题.所以它不会是一个高流量的页面,但它仍然不应该杀死构建记录集的数据库.
到目前为止,我有这个查询,需要几分钟的时间来处理(方式太长):
SELECT
tab1.id as id1,
tab1.creative as creative1,
tab2.id as id2,
tab2.creative as creative2
FROM
creatives tab1,
creatives tab2
WHERE
SOUNDEX(tab1.creative)= SOUNDEX(tab2.creative)
AND
tab1.id<>tab2.id
AND
tab1.id=(
SELECT
MAX(id)
FROM
creatives tab
WHERE
SOUNDEX(tab.creative)=SOUNDEX(tab1.creative))
Run Code Online (Sandbox Code Playgroud)
现在除了花费太长时间才能返回结果之外,结果有时候太模糊了.例如,它发现这些很好:
Convenery of Trades of Edinburgh | Convenery of Trades of Edinbubrgh
Crowdedlogic Theatre Company | Crowded Logic Theatre Company
Run Code Online (Sandbox Code Playgroud)
但这些似乎不合时宜
Daniel Cope | Dan Willis & Obie
David Williams | David Holmes
Run Code Online (Sandbox Code Playgroud)
那么,有更好的(更快,更不模糊)的方式吗?
我正在构建一个产品的旋转木马,下面有供应商按钮,可以过滤它们.因此,初始显示是所有产品徽标,但按下"Adobe"(例如)按钮,然后筛选出不是Adobe产品的所有内容,再次按下按钮不会过滤掉它.
我正在使用Slick和Slick,然后使用一些自定义的javascript来处理过滤.让我们从HTML开始.
<div class="container" >
<div class="row">
<div class="col-xs-12">
<div class="product-carousel">
<div class="item filter-apple"><img class="product" src="images/products/product-fcp7.png" /></div>
<div class="item filter-apple"><img class="product" src="images/products/product-fcpx.png" /></div>
<div class="item filter-apple"><img class="product" src="images/products/product-motion5.png" /></div>
<div class="item filter-adobe"><img class="product" src="images/products/product-aftereffects.png" /></div>
<div class="item filter-adobe"><img class="product" src="images/products/product-encore.png" /></div>
<div class="item filter-adobe"><img class="product" src="images/products/product-indesign.png" /></div>
<div class="item filter-avid"><img class="product" src="images/products/product-mediacomposer.png" /></div>
<div class="item filter-adobe"><img class="product" src="images/products/product-photoshop.png" /></div>
<div class="item filter-adobe"><img class="product" src="images/products/product-premierepro.png" /></div>
<div class="item filter-davinci"><img class="product" src="images/products/product-resolve.png" /></div>
<div class="item filter-autodesk"><img class="product" src="images/products/product-smoke.png" /></div>
</div>
<div class="vendors-wrapper"> …Run Code Online (Sandbox Code Playgroud) .htaccess ×1
carousel ×1
fuzzy-search ×1
javascript ×1
jquery ×1
mysql ×1
regex ×1
slider ×1
soundex ×1