gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:46:40 24 4
gpt4 key购买 nike

我有一家旧的 Peel 店,我搬到了 Prestashop 上。在上线之前,我想保留我在某些产品(大约 100 种产品)上获得的 Google 排名。

到目前为止,我在 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 未找到页面。据我所知,它不接受“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 live 时不必修改文件(并将 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>

最佳答案

您不能使用 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 文件中的重写引擎删除。

关于.htaccess - htaccess 从不再存在的文件永久重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9593679/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com