0

我已经编辑了我网站中的所有网址,下面是一个示例(它不必在 calipers 目录下)(下划线的数量也不是恒定的)

.com/Calipers/Insize_1108_1_2

.com/Calipers/Insize-1108-1-2

所以网址中只更改了 1 个字符,我应该如何修改我的 .htaccess ?

目前我的 htaccess 不包含除我的 cms 默认设置之外的任何内容,如下所示。

RewriteBase /
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

编辑:这是我试图做的,但没有奏效。

RewriteRule ^([^/]+)[_]([^/]+)$ $1-$2 [R=301,L]
4

1 回答 1

0
RedirectMatch 301 (/Calipers/Insize)_(\d+)_(\d+)_(\d+)$ $1-$2-$3-$4

RewriteBase /
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

untested yet,

also see here: htaccess regex directory to variable

edit

Your regex ^([^/]+)[_]([^/]+)$ doesn't match your url ".com/Calipers/Insize_1108_1_2"

With ^ the start of the string is marked. It would be better to look from the end don't touch the begin.

This results in

RewriteRule ^(.*)_(\d+)_(\d+)_(\d+)$ $1-$2-$3-$4 [R=301,L]

what isn't very different from my first solution.

It groups the three numbers at the end (with (\d+) for each one) and takes the rest until start (with (.*)).

于 2013-01-06T10:27:09.427 回答