当前位置: 动力学知识库 > 问答 > 编程问答 >

Can't figure out url rewrite regex

问题描述:

What I need to do is, to achieve redirect

from

domain.net/detail.php/?name=tRpPRU9dqVQ

to

domain.net/detail/?name=tRpPRU9dqVQ

in NGINX configuration.

Can't figure out proper regex. BTW, url might be with http/https.

Any suggestions?

网友答案:

Maybe with this:

<?php
$murl = "domain.net/detail.php/?name=tRpPRU9dqVQ"
echo preg_replace ("(https?://domain\.net/detail)\.php(/\?name=[a-zA-Z0-9]*)", "\0\1", $myurl)
?>

How do you want to achieve redirect ? Do you want to do it using PHP ?

网友答案:

You can use this redirect rule in your nginx configuration.

rewrite ^/detail.php/(.*)$ /detail/$1 redirect;

You can replace the redirect word at the end with permanent for a 301 permanent redirect code. You can find more details about this on their documentation.

分享给朋友:
您可能感兴趣的文章:
随机阅读: