0

I'm trying to redirect a query string from a URL (?u=user) to a static URL (/user).

So for example:

I currently have it set-up so that if someone types /user in at the end of the URL you'll see the profile page of that user.

What I want is to redirect the http://domain.com/profile.php?u=user to http://domain.com/user

How would I do this?

Thanks, in advance!

emmanuel
  • 9,607
  • 10
  • 25
  • 38
Chris
  • 1,574
  • 4
  • 16
  • 49
  • It seems like a pretty trivial extrapolation from the linked answer to what you need. Are you stuck on how to get out the query string (e.g. `$_GET['u']`) to use in building the new URL that you want to redirect to? – RobP Feb 21 '15 at 18:42
  • I'm stuck on the part where I redirect the `$_GET['u']` link to the static link. – Chris Feb 21 '15 at 18:50
  • 1
    I think it's as simple as `header('Location: /'.$_GET['u']);` – RobP Feb 21 '15 at 18:52
  • It's not exactly like that. I already have it where it redirects a `/user` link to the user's profile. So right now I want it so that whenever someone enters `profile.php?u=user` the link changes to `/user`. It won't be achieved by using that header code. – Chris Feb 21 '15 at 18:56
  • @ChrisDekker That's how it's done. If you want `/profile.php?u=user` to change to `/user`, then you have to perform a redirect. – Uyghur Lives Matter Feb 21 '15 at 19:01
  • How would I make it so that when someone tries to load the page `/profile.php?u=user` it redirects them to `/user`? If I put the `header` function in the page, nothing happens. – Chris Feb 21 '15 at 19:11
  • Fixed it using `$url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; if (false !== strpos($url,'?u=')) { $username = strtolower($username); echo ""; } else { // Do Nothing }` – Chris Feb 21 '15 at 21:30

0 Answers0