将ID传递给另一个URL

时间:2014-12-30 23:14:23

标签: apache .htaccess mod-rewrite

希望通过重写实现以下目标:

www.example.com/sub/details/ A12345 重写为 - > www.example.com/sub/processing.php?id=A12345

我有以下内容,但显然这还没有结果:

RewriteRule ^details/(\d*)$ http://www.example.com/sub/processing.php?id=%1

1 个答案:

答案 0 :(得分:0)

您可以将此代码放入htaccess(位于sub文件夹中)

RewriteEngine On
RewriteBase /sub/

# redirect /sub/processing.php?id=XXX to /sub/details/XXX
RewriteCond %{THE_REQUEST} /processing\.php\?id=([^\s&]+)\s [NC]
RewriteRule ^ details/%1? [R=301,L]

# internally rewrite /sub/details/XXX to /sub/processing.php?id=XXX
RewriteRule ^details/([^/]+)$ processing.php?id=$1 [L]

注意:如果要保持两种格式都处于活动状态,可以评论/删除这两行

RewriteCond %{THE_REQUEST} /processing\.php\?id=([^\s&]+)\s [NC]
RewriteRule ^ details/%1? [R=301,L]