1

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.

5
  • 1
    Whats stopping you from doing it manually? Commented Sep 6, 2010 at 9:49
  • Nothing, just wondered if there was a way of doing it through PHP :) Commented Sep 6, 2010 at 9:50
  • I just need to replace ?page= with a '/' basically but even if the page is something different like action Commented Sep 6, 2010 at 9:51
  • Any half decent IDE with a search and replace function should handle this with ease. Commented Sep 6, 2010 at 9:51
  • You could write a utility function which converted between the plain and "SEF" versions, then if your scheme changed you could update the function and not have to manually change the links again. Commented Sep 6, 2010 at 9:54

1 Answer 1

2
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;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.