2014-06-11 98 views
0

我需要建立一個301重定向我的htaccess的文件中,該問題是鏈接有特殊字符(?):創造一個htaccess的重定向包含特殊字符

<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> 

什麼是最好的方式將每個這些網址重定向到正確的目的地?

回答

3

之後的所有字符?標誌是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] 

Adob​​e的規則將匹配:

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

+0

我會怎樣處理這些類型的網址:used-machinery/en/finlay/used-machinery-item?000549:798-double-deck-skin-trommel-scre en –

+0

我編輯了我的答案,我在RewriteCond中添加了「:」符號 –

+0

您已添加'?'在一些網址之後和'$'之後,有什麼區別?他們應該只有'?' –