繁体   English   中英

正则表达式htaccess

[英]Regular expression htaccess

我需要一个简单的正则表达式来匹配ASP页面并将其重定向到另一个页面。

例如

/showdetails.asp?id=1334

/page-redirect.php?page=showdetails&id=1334

这是我到目前为止似乎不起作用

RedirectMatch 301 ^/(.*)\.asp?id=(.*)$ /page-redirect.php?page=$1&id=$2

在哪里

RedirectMatch 301 ^/(.*)\.asp$ /page-redirect.php?page=$1

确实有效。


没关系自己解决它,需要逃脱吗?

    RedirectMatch 301 ^/(.*)\.asp\?id=(.*)$ /page-redirect.php?page=$1&id=$2

你的

301 ^/(.*)\.asp?id=(.*)$ /page-redirect.php?page=$1&id=$2

正确

301 ^/(.*)\.asp\?id=(.*)$ /page-redirect.php?page=$1&id=$2

考虑

301 ^/([^/]+)\.asp\?id=(\d+)$ /page-redirect.php?page=$1&id=$2

逃脱? asp?id ,也许。

不能使用RedirectMatch指令来匹配查询字符串,因此,所有建议的解决方案都无法使用

您需要使用基于mod_rewrite的规则。

RewriteEngine On

RewriteCond %{QUERY_STRING} ^id=([^&]+)$ [NC]
RewriteRule ^([^.]+)\.asp$ /page-redirect.php?page=$1&id=%1 [L,NC,R=301]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM