我需要在我的htaccess文件中创建301重定向,问题是链接有(?)特殊字符:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^news/news-item?blue-spares-appoints-stuart-truckel-as-sales-director?$ http://www.example.com/news [R=301,L]
RewriteRule ^news/news-item?hugely-successful-scot-plant-for-blue-scotland?$ http://www.example.com/news [R=301,L]
RewriteRule ^news/news-item?port-of-workington-takes-specialist-fuchs-materials-handler?$ http://www.example.com/news [R=301,L]
RewriteRule ^news/news-item?blue-spares-go-green-with-new-shredder?$ http://www.example.com/news [R=301,L]
RewriteRule ^used-machinery/en/shredders/used-machinery-item?000739:beast-bandit-2860?$ http://www.example.com/machinery [R=301,L]
RewriteRule ^about-us/careers/careers-item?project-manager-blue-machinery-london-ltd http://www.example.com/about [R=301,L]
RewriteRule ^news/news-item?thompsons-plant-hire-continues-allegiance-to-doppstadt-and-blue-machinery http:// http://www.example.com/news [R=301,L]
RewriteRule ^used-machinery/en/finlay/used-machinery-item?000549:798-double-deck-skin-trommel-screen http://www.example.com/machinery [R=301,L]
RewriteRule ^used-machinery/en/screeners/used-machinery-item?000549:798-double-deck-skin-trommel-screen http://www.example.com/machinery [R=301,L]
RewriteRule ^product-videos/shredders/doppstadt-ak-range/ http://www.example.com/product-videos [R=301,L]
RewriteRule ^product-videos/shredders/doppstadt-ak-range/?1 http://www.example.com/product-videos [R=301,L]
RewriteRule ^product-videos/shredders/doppstadt-ak-range/?4 http://www.example.com/product-videos [R=301,L]
RewriteRule ^product-videos/shredders/doppstadt-ak-range/?3 http://www.example.com/product-videos [R=301,L]
RewriteRule ^product-videos/shredders/doppstadt-ak-range/?7 http://www.example.com/product-videos [R=301,L]
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
将每个网址重定向到正确的目的地的最佳方法是什么?
答案 0 :(得分:3)
之后的所有人物? sign是QUERY_STRING的一部分,您必须在规则之前为查询字符串添加条件:
RewriteCond %{QUERY_STRING} ^[0-9a-z\-\:]+$
RewriteRule ^product-videos/shredders/doppstadt-ak-range/? http://www.example.com/product-videos [R=301,L]
RewriteRule ^news/news-item http://www.example.com/news [R=301,L]
RewriteRule ^used-machinery/en/shredders/used-machinery-item$ http://www.example.com/machinery [R=301,L]
RewriteRule ^about-us/careers/careers-item$ http://www.example.com/about [R=301,L]
RewriteRule ^news/news-item$ http:// http://www.example.com/news [R=301,L]
RewriteRule ^used-machinery/en/finlay/used-machinery-item http://www.example.com/machinery [R=301,L]
RewriteRule ^used-machinery/en/screeners/used-machinery-item http://www.example.com/machinery [R=301,L]
adobe规则将匹配:
news/news-item?blue-spares-appoints-stuart-truckel-as-sales-director
news/news-item?hugely-successful-scot-plant-for-blue-scotland
news/news-item?port-of-workington-takes-specialist-fuchs-materials-handler
news/news-item?blue-spares-go-green-with-new-shredder
product-videos/shredders/doppstadt-ak-range/?1
product-videos/shredders/doppstadt-ak-range/?4
product-videos/shredders/doppstadt-ak-range/?3
product-videos/shredders/doppstadt-ak-range/?7
和其他网址
请参阅RewriteCond文档: http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#RewriteCond