使用静态URL的一部分使用.htaccess重新记录到动态URL

使用静态URL的一部分使用.htaccess重新记录到动态URL,.htaccess,mod-rewrite,redirect,.htaccess,Mod Rewrite,Redirect,通常是另一种方式,但我需要将静态URL重定向到动态URL,作为第一个URL的可变部分 我需要重定向: http:/example.com/sub1/sub-2/2014147-test-page-45x.html http:/example.com/sub1/sub-6/8014149-test-24page.html http:/example.com/sub1/sub-25/7514157-58test-page.html 到 我知道我需要使用%{REQUEST_URI},但我无法将其组合

通常是另一种方式,但我需要将静态URL重定向到动态URL,作为第一个URL的可变部分

我需要重定向:

http:/example.com/sub1/sub-2/2014147-test-page-45x.html
http:/example.com/sub1/sub-6/8014149-test-24page.html
http:/example.com/sub1/sub-25/7514157-58test-page.html

我知道我需要使用%{REQUEST_URI},但我无法将其组合在一起

任何帮助都将不胜感激


谢谢。

假设您的.htaccess位于example.com的根目录下,添加以下内容即可

RewriteEngine On
RewriteBase /

RewriteRule ^sub1/[^/]+/(\d+).*$ sub1/testing.php?s=$1 [R,L]
这应该起作用:

RewriteEngine on
RewriteRule ^sub1/(.*)/([0-9]+)-(.*)$ /sub1/testing.php?s=$2 [R=301,L]
RewriteEngine on
RewriteRule ^sub1/(.*)/([0-9]+)-(.*)$ /sub1/testing.php?s=$2 [R=301,L]