2011-04-11 56 views
0

国防部重写正则表达式我需要一个正则表达式,我可以在一个.htaccess的文件用来重写:只有用于通过.htaccess的

http://www.sample.com/dir/1-2-3.php

1 =小写字母,没有限制多少

2 =字母数字(唯一小写字母)和短划线,有多少字符

上多少个字符

3 =字母数字(仅大写字母),没有限制没有限制

(注:1,2,3是故意的,并且将存在于URL之间的破折号)

http://www.sample.com/dir/sub/page.php?v=ABC12345

哪里ABC12345是#3从原始URL。

回答

0

如果我的理解正确,以下应该工作。

RewriteEngine On 
RewriteRule ^([a-z]*)-([a-z0-9-]*)-([A-Z0-9]*)\.php /$1/$2.php?v=$3 [L] 

希望这会有所帮助。

0

试试这个规则在你的.htaccess:

Options +FollowSymLinks 
RewriteEngine on 
RewriteRule ^dir/([a-z]*)-([a-z0-9-]*)-([A-Z0-9]*)\.php$ /dir/sub/page.php?v=$3 [R=301,L,NE,QSA] 

R=301 will redirect with https status 301 
L will make last rule 
NE is for no escaping query string 
QSA flag will make sure to append existing query parameter with additional query parameters 

$3 is 3rd capture group in your REQUEST_URI