htaccess永久重定向从不再存在的文件

时间:2012-03-06 23:41:40

标签: .htaccess redirect seo prestashop permanent

我找到了一家旧的Peel商店,我搬到了Prestashop。在切换它之前,我想保留一些产品的谷歌排名(大约100种产品)。

到目前为止,我在Prestashop pre-prod服务器上进行了测试,其域名如“mywebsite.com/~subfolder/”(由托管公司强制)。所有产品都从Peel进口到Prestashop。

我认为这很简单

Options +FollowSymlinks    
RewriteEngine on 
RedirectPermanent /~subfolder/achat/product_detail.php?id=300 http://www.mywebsite.com/~subfolder/my/new/url-300.html

会起作用,但我总是被重定向到Prestashop not found页面。据我所知,它不接受“achat / product_detail.php”不存在的事实。

我也试过

RewriteRule ^/~subfolder/achat/produit_details.php?id=110$ /~subfolder/layette-en-laine-et-soie/110-brassiere-laine-et-soie.html [L,R=301]

效果不佳。

处理此问题的正确方法是什么?如果可能的话,以相对的方式表示我不希望在我切换Prestashop时更改文件(并将http://mywebsite.com/~subfolder更改为http://www.mywebsite.com)。

非常感谢任何帮助!

谢谢,

尼古拉斯

PS:如果需要,在prestashop生成的htaccess文件下面(我删除了上面提到的测试):

# .htaccess automaticaly generated by PrestaShop e-commerce open-source solution
# WARNING: PLEASE DO NOT MODIFY THIS FILE MANUALLY. IF NECESSARY, ADD YOUR SPECIFIC CONFIGURATION WITH THE HTACCESS GENERATOR IN BACK OFFICE
# http://www.prestashop.com - http://www.prestashop.com/forums

SetEnv PHP_VER 5_TEST
SetEnv REGISTER_GLOBALS 0

AuthUserFile    /XXXX
AuthGroupFile /dev/null
AuthName "Veuillez vous identifier"
AuthType Basic


require valid-user

<IfModule mod_rewrite.c>

# URL rewriting module activation
RewriteEngine on

# URL rewriting rules
RewriteRule ^api/?(.*)$ /~subfolder/webservice/dispatcher.php?url=$1 [QSA,L]
RewriteRule ^([a-z0-9]+)\-([a-z0-9]+)(\-[_a-zA-Z0-9-]*)/[_a-zA-Z0-9-]*\.jpg$ /~subfolder/img/p/$1-$2$3.jpg [L]
RewriteRule ^([0-9]+)\-([0-9]+)/[_a-zA-Z0-9-]*\.jpg$ /~subfolder/img/p/$1-$2.jpg [L]
RewriteRule ^([0-9])(\-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*\.jpg$ /~subfolder/img/p/$1/$1$2.jpg [L]
RewriteRule ^([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*\.jpg$ /~subfolder/img/p/$1/$2/$1$2$3.jpg [L]
RewriteRule ^([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*\.jpg$ /~subfolder/img/p/$1/$2/$3/$1$2$3$4.jpg [L]
RewriteRule ^([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*\.jpg$ /~subfolder/img/p/$1/$2/$3/$4/$1$2$3$4$5.jpg [L]
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*\.jpg$ /~subfolder/img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6.jpg [L]
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*\.jpg$ /~subfolder/img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7.jpg [L]
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*\.jpg$ /~subfolder/img/p/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8.jpg [L]
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*\.jpg$ /~subfolder/img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9.jpg [L]
RewriteRule ^c/([0-9]+)(\-[_a-zA-Z0-9-]*)/[_a-zA-Z0-9-]*\.jpg$ /~subfolder/img/c/$1$2.jpg [L]
RewriteRule ^c/([a-zA-Z-]+)/[a-zA-Z0-9-]+\.jpg$ /~subfolder/img/c/$1.jpg [L]
RewriteRule ^([0-9]+)(\-[_a-zA-Z0-9-]*)/[_a-zA-Z0-9-]*\.jpg$ /~subfolder/img/c/$1$2.jpg [L]
RewriteRule ^([0-9]+)\-[a-zA-Z0-9-]*\.html /~subfolder/product.php?id_product=$1 [QSA,L]
RewriteRule ^[a-zA-Z0-9-]*/([0-9]+)\-[a-zA-Z0-9-]*\.html /~subfolder/product.php?id_product=$1 [QSA,L]
RewriteRule ^([0-9]+)\-[a-zA-Z0-9-]*(/[a-zA-Z0-9-]*)+ /~subfolder/category.php?id_category=$1&noredirect=1 [QSA,L]
RewriteRule ^([0-9]+)\-[a-zA-Z0-9-]* /~subfolder/category.php?id_category=$1 [QSA,L]
RewriteRule ^([0-9]+)__([a-zA-Z0-9-]*) /~subfolder/supplier.php?id_supplier=$1 [QSA,L]
RewriteRule ^([0-9]+)_([a-zA-Z0-9-]*) /~subfolder/manufacturer.php?id_manufacturer=$1 [QSA,L]
RewriteRule ^content/([0-9]+)\-([a-zA-Z0-9-]*) /~subfolder/cms.php?id_cms=$1 [QSA,L]
RewriteRule ^content/category/([0-9]+)\-([a-zA-Z0-9-]*) /~subfolder/cms.php?id_cms_category=$1 [QSA,L]
RewriteRule ^page-non-trouvee$ /~subfolder/404.php [QSA,L]
RewriteRule ^adresse$ /~subfolder/address.php [QSA,L]
RewriteRule ^adresses$ /~subfolder/addresses.php [QSA,L]
RewriteRule ^authentification$ /~subfolder/authentication.php [QSA,L]
RewriteRule ^meilleures-ventes$ /~subfolder/best-sales.php [QSA,L]
RewriteRule ^panier$ /~subfolder/cart.php [QSA,L]
RewriteRule ^contactez-nous$ /~subfolder/contact-form.php [QSA,L]
RewriteRule ^bons-de-reduction$ /~subfolder/discount.php [QSA,L]
RewriteRule ^suivi-commande-invite$ /~subfolder/guest-tracking.php [QSA,L]
RewriteRule ^historique-des-commandes$ /~subfolder/history.php [QSA,L]
RewriteRule ^identite$ /~subfolder/identity.php [QSA,L]
RewriteRule ^fabricants$ /~subfolder/manufacturer.php [QSA,L]
RewriteRule ^mon-compte$ /~subfolder/my-account.php [QSA,L]
RewriteRule ^nouveaux-produits$ /~subfolder/new-products.php [QSA,L]
RewriteRule ^commande$ /~subfolder/order.php [QSA,L]
RewriteRule ^details-de-la-commande$ /~subfolder/order-follow.php [QSA,L]
RewriteRule ^commande-rapide$ /~subfolder/order-opc.php [QSA,L]
RewriteRule ^avoirs$ /~subfolder/order-slip.php [QSA,L]
RewriteRule ^mot-de-passe-oublie$ /~subfolder/password.php [QSA,L]
RewriteRule ^promotions$ /~subfolder/prices-drop.php [QSA,L]
RewriteRule ^recherche$ /~subfolder/search.php [QSA,L]
RewriteRule ^plan-du-site$ /~subfolder/sitemap.php [QSA,L]
RewriteRule ^magasins$ /~subfolder/stores.php [QSA,L]
RewriteRule ^fournisseurs$ /~subfolder/supplier.php [QSA,L]
</IfModule>

# Catch 404 errors
ErrorDocument 404 /~subfolder/404.php

<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType text/css "access plus 1 week"
    ExpiresByType text/javascript "access plus 1 week"
    ExpiresByType application/javascript "access plus 1 week"
    ExpiresByType application/x-javascript "access plus 1 week"
    ExpiresByType image/x-icon "access plus 1 year"
</IfModule>

FileETag INode MTime Size
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE text/javascript
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/x-javascript
</IfModule>

2 个答案:

答案 0 :(得分:0)

您无法使用RewriteRule与查询字符串匹配,并且您无法在Redirect指令中包含查询字符串。您需要使用RewriteCond作为查询字符串:

RewriteCond %{QUERY_STRING} ^id=110$ 
RewriteRule ^~subfolder/achat/produit_details.php$ /~subfolder/layette-en-laine-et-soie/110-brassiere-laine-et-soie.html [L,R=301]

请注意,您还需要删除匹配中的前导 / ,因为它会被.htaccess文件中的重写引擎删除。

答案 1 :(得分:0)

我终于回答了我的问题:如果上面详细说明,有一个有效重定向的解决方案如下:

RewriteCond %{QUERY_STRING} ^id=110$ 
RewriteRule ^achat/produit_details.php$ /~subfolder/layette-en-laine-et-soie/110-brassiere-laine-et-soie.html [L,R=301]

要为需要重定向的每个产品ID执行此操作 希望它会有所帮助!