0

私は自分のウェブサイトのすべてのURLを編集しました。を以下に示します (キャリパー ディレクトリの下にある必要はありません) (また、アンダースコアの数は一定ではありません)。

.com/キャリパー/Insize_1108_1_2

.com/キャリパー/Insize-1108-1-2

URL で変更されるのは 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]

まだテストされていない、

ここも参照してください:変数へのhtaccess正規表現ディレクトリ

編集

正規表現^([^/]+)[_]([^/]+)$が URL「.com/Calipers/Insize_1108_1_2」と一致しません

文字列の開始^がマークされています。最初から触らず、最後から見たほうがいいです。

これにより、

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

私の最初の解決策と大差ありません。

最後に 3 つの数字をグループ化し ( (\d+)for each one)、残りを start (with (.*)) まで取得します。

于 2013-01-06T10:27:09.427 に答える