Access the same page in multiple "pathname"

Asked

Viewed 29 times

0

I’m creating pages for a site that would show a particular person’s profile using a path in the url (pathname)

Example:

  • demo.com/page/Iagobruno
  • demo.com/page/Rodriggodell

All these domains would show the same page (in php) and on this page would be put a code to search for information from the cited profile in this url path, in this case: Iagobruno or Rodriggodell.

  • What you researched/tried so far ?

  • I don’t know how to search this, I’m kind of new in php, but I think this is how social networks do with users' profiles: same pages and different content.

  • 1

    see Rodrigo’s answer, it’s right on this line. Actually the one who does the magic is the webserver

1 answer

5


Use mod_rewrite. As this you can redirect the requests from:

demo.com/page/IagoBruno for demo.com/page.php?username=IagoBruno

or:

demo.com/page/RodriggoDell for demo.com/page.php?username=RodriggoDell

In this particular case, the mod_rewrite configuration would look like this:

RewriteEngine On
RewriteBase /
RewriteRule ^page/([A-Za-z0-9_-]+) /page.php?username=$1 [L]

Obviously the module should be enabled in Apache.

  • That code would be in the . htaccess file?

  • 1

    It can be either in the virtual host configuration or in . htaccess, as long as Allowoverride is enabled

  • It worked here, thank you! =)

  • 1

    You’re welcome! Don’t forget to validate the answer. :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.