简单的mod_rewrite重写规则凌乱遗留的URL重写、凌乱、规则、简单

由网友(指尖残余的微凉﹏)分享简介:推出一个新网站,新的客户端。他们的旧网站大约有50种产品,不幸的是,旧的产品名称不匹配到新的URL模式Launching a new website for a new client. Their old site has about 50 products and unfortunately, the old pr...

推出一个新网站,新的客户端。他们的旧网站大约有50种产品,不幸的是,旧的产品名称不匹配到新的URL模式

Launching a new website for a new client. Their old site has about 50 products and unfortunately, the old product names do not match up to the new URL pattern

旧网址的例子:

example.com/products.aspx?category=Foo&product=SuperLongNoBreakProductNameIDDescription

example.com/products.aspx?category=Foo&product=ProductNameDescription&var1=1293.123

example.com/products.aspx?category=Bar&product=ProductCategoryProdNameRandomNumbers

(旧网址的有时打150 +字符。)

(The old URL's are sometimes hitting 150+ characters.)

新的URL:

example.com/products/category/actual-product-name

example.com/products/category/actual-product-name

有没有一套的,可识别的模式从旧的产品名称,转到新的。有该类别

There's no set, recognizable pattern to go from the old product name to the new one. There is for the category.

我已经试过简单mod_alias中的重定向,但明白,我需要一个重写规则来代替。但我有问题。所有我需要的是一个1对1重定向为每个50的URL的。我想我可以做这样的事情:

I've tried simple mod_alias Redirects, but understand that I need a RewriteRule instead. But I'm having problems. All I need is a 1-to-1 redirect for each of these 50 URL's. I thought I could do something like:

RewriteRule ^/products.aspx?category=Foo&product=ProductName
    /products/category/new-product-name/  [R=301,NC]

但是,这是行不通的。我知道这应该是简单,但我坚持。任何想法?

But that isn't working. I know this should be simple, but I am stuck. Any ideas?

推荐答案

使用下面为您重定向URL的其余部分的图案。请注意,例如特殊字符转义和空间 通过增加一个 在他们面前

Use the pattern below for the rest of your redirect urls. Note that you escape special characters e.g. ? , . and space by adding a in front of them

RewriteEngine on
RewriteBase /

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /products.aspx?category=Foo&product=SuperLongNoBreakProductNameIDDescription [NC]
RewriteRule ^ /products/category/new-product-name/  [R=301,NC]
阅读全文

相关推荐

最新文章