[英]htaccess: 301 redirect removing part of url
I'm trying to move my shop from Shopify to Woocommerce.我正在尝试将我的商店从 Shopify 转移到 Woocommerce。 I have redirections 301 to do before moving my domain name.
在移动我的域名之前,我有重定向 301 要做。 In order not to make the .htaccess file heavy, I would like to use regex to remove part from urls.
为了不使 .htaccess 文件变重,我想使用正则表达式从 url 中删除部分。
I would like to redirect我想重定向
From:从:
https://"my-shop.com"/ products /"product-name" https://"my-shop.com"/ products /"product-name"
To:到:
https://"my-shop.com"/"product-name" https://"my-shop.com"/"product-name"
And和
From:从:
https://"my-shop.com"/ collections /"product-category-name" https://"my-shop.com"/ collections /"product-category-name"
To:到:
https://"my-shop.com"/"product-category-name" https://"my-shop.com"/"product-category-name"
So to remove "products" or "collections"所以要删除“产品”或“集合”
First problem: I absolutely don't know how to code that... I tried to understand by looking on the web, found some code, but it's too complicated for me, I did'nt success to adapt it to my problem.第一个问题:我完全不知道如何编码......我试图通过查看网络来理解,找到了一些代码,但对我来说太复杂了,我没有成功地适应我的问题。 If I'm not wrong, to remove "products" for example, it would look like that:
如果我没有错,例如删除“产品”,它看起来像这样:
RewriteEngine on
RewriteRule ^products/(.*)$ /$1 [R=301,L]
Second problem: If I changed a product name or product category, its url should not follow this rule but redirect to a totally different url.第二个问题:如果我更改了产品名称或产品类别,其 url 不应遵循此规则,而是重定向到完全不同的 url。 Can I still use regex for other products and product categories, but add a redirection 301 before so it could work for the product / category I modified?
我是否仍然可以将正则表达式用于其他产品和产品类别,但在之前添加重定向 301 以便它可以用于我修改的产品/类别?
Could you please try following.你能不能试试以下。 Following is looking for
products
OR collections
keywords from URL.以下是从 URL 中查找
products
或collections
关键字。
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(products|collections)/(.*)/?$ /$2 [NC,L]
OR use this rule in case you could have any string in place of products
or collections
.或者,如果您可以使用任何字符串代替
products
或collections
使用此规则。
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/(.*)/?$ /$2 [NC,L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.