开发者

PHP Replace Variables in URL

开发者 https://www.devze.com 2023-01-14 19:18 出处:网络
I wondered 开发者_Python百科if it was possible to rewrite a URL so designed for the rewrite wrote in htaccess

I wondered 开发者_Python百科if it was possible to rewrite a URL so designed for the rewrite wrote in htaccess

e.g.

I have the URL: http://example.com/page.php?page=5&action=something

But I want to change the URL to: example.co m/page/5/something

This is just for the href, the htaccess bit is solved.


function rewritelink($link){
    $link = str_replace('.php','', $link);
    $pattern = "/\?[^=]*=/";
    $replacement = '/';
    $link = preg_replace($pattern, $replacement, $link);
    $pattern = "/\&[^=]*=/";
    $replacement = '/';
    $link = preg_replace($pattern, $replacement, $link);
    return $link;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消