Apache 使用正则表达式自定义重定向?

Apache 使用正则表达式自定义重定向?,apache,.htaccess,redirect,Apache,.htaccess,Redirect,我想重定向以下URL结构: /vehicle_details.php?veh_id=918 致: 我需要它在车辆id有任何问题时执行它,因此它会将它们全部重定向。感谢@naomi的创意 由于vehicle\u details.php是一个将被删除的非常旧的文件,我简单地创建了一个新文件,其中包含: <?php // old website redirects header("Location: http://www.example.com/my/url/");

我想重定向以下URL结构:

/vehicle_details.php?veh_id=918
致:


我需要它在车辆id有任何问题时执行它,因此它会将它们全部重定向。

感谢@naomi的创意

由于
vehicle\u details.php
是一个将被删除的非常旧的文件,我简单地创建了一个新文件,其中包含:

<?php 
    // old website redirects
    header("Location: http://www.example.com/my/url/");
    exit;
?>

通过
httpd.conf
启用mod_rewrite和.htaccess,然后将此代码放入
文档根目录下的
.htaccess

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+vehicle_details\.php\?veh_id=[^\s]+ [NC]
RewriteRule ^ http://www.example.co.uk/my/url? [R=302,L]

确认其工作正常后,将
R=302
更换为
R=301
。在测试mod_重写规则时,请避免使用
R=301
(永久重定向)。

是否可以不考虑查询字符串而直接重定向/vehicle_details.php?如果没有,可能需要重定向匹配-是否要将车辆id传递到新的url?是
/my/url
是文本还是一些动态字符串?
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+vehicle_details\.php\?veh_id=[^\s]+ [NC]
RewriteRule ^ http://www.example.co.uk/my/url? [R=302,L]