这是在根目录的 .htaccess 文件中使用 mod_rewrite 指令的想法:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /(.*)-10551-10051-(.*)/?
RewriteRule .* %1-10551-10551-%2 [R=301,L]
更新
# Enable rewriting engine
RewriteEngine On
# Specify the URL prefix
RewriteBase /
# Prevent loops
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Match any URL the holds this string: -10551-10051-, splitting it in 3 parts
# The segment before the string to match, the string itself and the next segment up to the first slash or nothing
RewriteCond %{REQUEST_URI} ^/(.*)-10551-10051-([^/]+)/?
# Assemble the substitution URL like this: first segment-modified string-last segment. Rewrite.
RewriteRule .* %1-10551-10551-%2 [R=301,L]
这将重定向
http://example.com/Folder1/Folder2/anything1-10551-10051-anything2
至:
http://example.com/Folder1/Folder2/anything1-10551-10551-anything2
我假设您想要一个永久且可见的重定向。如果不是这种情况,请R=301
删除[R=301,L]