如何使用htaccess重写URL?

时间:2009-10-03 08:40:46

标签: apache .htaccess mod-rewrite url-rewriting

如何重写以下网址:

http://www.myurl.com/job/Accounting-Clerk-at-Department-of-Workforce-Services-in-Salt-Lake-City,-UT-1b6117567108f5a2

进入这些组件:

query = Accounting Clerk;
cmp = Department of Workforce Services;
location = Salt Lake City, UT;
key = 1b6117567108f5a2;

要获得此结果:

index.php?q=$query&cmp=$cmp&l=$location&key=$key

2 个答案:

答案 0 :(得分:4)

试试这个mod_rewrite规则:

RewriteEngine on
RewriteRule ^job/([^/]+)-at-([^/]+)-in-([^/]+)-([0-9a-f]+)$ index.php?q=$1&cmp=$2&l=$3&key=$4

答案 1 :(得分:1)

RewriteEngine on
RewriteBase /

RewriteRule job/([^.]+)-in-([^.]+) index.php?var1=$1&var2ext=$2

等继续这样