Apache URL中的可选参数-重写规则

Apache URL中的可选参数-重写规则,apache,.htaccess,mod-rewrite,apache2.2,Apache,.htaccess,Mod Rewrite,Apache2.2,我不知道“可选参数”这个词是否正确地描述了我的情况。这是我需要的 我为URL重定向编写了以下规则: RewriteRule ^product/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)$ product/?sid=$2&pid=$3&title=$1&src=$4 [NC,L] 基本上,这将重定向如下内容 http://localdomain.com/product/Golf-Bats/

我不知道“可选参数”这个词是否正确地描述了我的情况。这是我需要的

我为URL重定向编写了以下规则:

RewriteRule ^product/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)$ product/?sid=$2&pid=$3&title=$1&src=$4 [NC,L]
基本上,这将重定向如下内容

http://localdomain.com/product/Golf-Bats/abc123/def456/stringy
http://localdomain.com/product/?sid=abc123&pid=def456&title=Golf-Bats&src=stringy
差不多

http://localdomain.com/product/Golf-Bats/abc123/def456/stringy
http://localdomain.com/product/?sid=abc123&pid=def456&title=Golf-Bats&src=stringy
我要做的是编写一个规则,它接受额外的/可选的/可能无限多的参数(//类型构造),但仍然重定向到相同的URL

这意味着以下URL:

http://localdomain.com/product/Golf-Bats/abc123/def456/stringy
http://localdomain.com/product/Golf-Bats/abc123/def456/stringy/rand1
http://localdomain.com/product/Golf-Bats/abc123/def456/stringy/rand1/rand2
http://localdomain.com/product/Golf-Bats/abc123/def456/stringy/rand1/rand2/rand3
etc.
应该全部指向URL吗

http://localdomain.com/product/?sid=abc123&pid=def456&title=Golf-Bats&src=stringy
有什么想法吗?

使用这个规则——它将使第六个和更多的路径段成为“可选的”:

此规则将所有这些URL视为相同的(将重定向到相同的URL):

  • 我已经在模式中将
    A-Za-z
    替换为
    A-z
    ,因为您已经有了
    [NC]
    标志(忽略大小写)

  • 请记住,从SEO的角度来看,这类URL通常不好-我强烈建议使用
    指定适当的URL,以避免搜索引擎重复内容:

  • 该“可选”部分将丢失/不会按照请求传递到新URL