ITg
ITg

Reputation: 138

Convert URL with querystring to "Search Engine Friendly" URL

I wondered 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.com/page/5/something

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

Upvotes: 1

Views: 591

Answers (1)

ITg
ITg

Reputation: 138

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;
}

Upvotes: 2

Related Questions