简单的mod_rewrite重写规则凌乱遗留的URL [英] Simple mod_rewrite RewriteRule for messy legacy url's

查看:126
本文介绍了简单的mod_rewrite重写规则凌乱遗留的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

推出一个新网站,新的客户端。他们的旧网站大约有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

旧网址的例子:

<$c$c>example.com/products.aspx?category=Foo&product=SuperLongNoBreakProductNameIDDescription

<$c$c>example.com/products.aspx?category=Foo&product=ProductNameDescription&var1=1293.123

<$c$c>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]

这篇关于简单的mod_rewrite重写规则凌乱遗留的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆