使用静态URL的一部分使用.htaccess重定向到动态URL

时间:2014-05-07 18:30:56

标签: .htaccess mod-rewrite redirect

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

我需要重定向:

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

http://example.com/sub1/testing.php?s=2014147
http://example.com/sub1/testing.php?s=8014149
http://example.com/sub1/testing.php?s=7514157

我知道我需要使用%{REQUEST_URI},但我不能把它放在一起。

任何帮助将不胜感激。

感谢。

2 个答案:

答案 0 :(得分:1)

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

RewriteEngine On
RewriteBase /

RewriteRule ^sub1/[^/]+/(\d+).*$ sub1/testing.php?s=$1 [R,L]

答案 1 :(得分:0)

这应该有效:

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