How do I use URL directories as variables?

magneticstain

I'm wondering how sites like Pastebin and Twitter pass (what I assume to be) variables via the URL.

For example, take a Pastebin URL. It has the format of http://www.pastebin.com/<PASTE_UID>. I'm wondering how they parse the UID without the server trying to treat it like an actual page. I can't imagine they generate individual files for each post.

I know this is most likely a combination of mod_rewrite and parsing the variable from the URL on the backend to extract the variable, but I'm at a loss on how to do it.

Pedro Lobito

As you said, you can use apache mod_rewrite, i.e.:

Create an .htaccess file on the root of your website with the following content:

RewriteEngine on
RewriteRule ^uid/(.*)$ /uid.php?uid=$1 [NC]

If, for example, the url is http://yoursite.com/uid/123456, apache will send the value 123456 via $_GET request to uid.php, you can get the uid value using:

<?php
if(!empty($_GET['uid'])){
  $uid = $_GET['uid'];
  //123456 
}
?>

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

How do I import data from Activie directories through LDAP URL

분류에서Dev

Makefiles - How do I use an eval'd variables with ifndef/ifdef?

분류에서Dev

How do I deal with directories that have spaces in their names from `find`?

분류에서Dev

How do I display url

분류에서Dev

how can I do this with the variables in lua?

분류에서Dev

How do I configure environment variables in cmder?

분류에서Dev

How do I use MapStateListener?

분류에서Dev

How can I get PyCharm to use the Vagrant Directories rather than my development machines?

분류에서Dev

How do I execute this find command multiple times throughout many directories with the ampersand '&' command?

분류에서Dev

How do I give files and directories created by FTP the correct permissions for Apache to read and write them?

분류에서Dev

How do I delete all empty directories in a directory from the command line?

분류에서Dev

How do you use UIView with properties or variables inherited from ViewController?

분류에서Dev

How do I use OR with if statements in regards to strings

분류에서Dev

How do i use Blazor components in the code?

분류에서Dev

Python: How do i use itertools?

분류에서Dev

How do I use runit with zookeeper

분류에서Dev

How do I use Firefox cookies with Wget?

분류에서Dev

How do I use the GeometryConstraint class?

분류에서Dev

How do I make use of rotation matrices?

분류에서Dev

How do I configure ActiveJob to use Resque?

분류에서Dev

How do i use SetPixel on a new Bitmap?

분류에서Dev

How do i get cURL to use https

분류에서Dev

How do I use "<<" with my own struct?

분류에서Dev

What is fileAPI ? How do I use it with angular?

분류에서Dev

How do I open and use phpmyadmin?

분류에서Dev

How do I configure Docker to use ZFS?

분류에서Dev

How do I use the latest GCC on Ubuntu?

분류에서Dev

How do I use man pages to learn how to use commands?

분류에서Dev

How do I communicate variables between methods in Python?

Related 관련 기사

  1. 1

    How do I import data from Activie directories through LDAP URL

  2. 2

    Makefiles - How do I use an eval'd variables with ifndef/ifdef?

  3. 3

    How do I deal with directories that have spaces in their names from `find`?

  4. 4

    How do I display url

  5. 5

    how can I do this with the variables in lua?

  6. 6

    How do I configure environment variables in cmder?

  7. 7

    How do I use MapStateListener?

  8. 8

    How can I get PyCharm to use the Vagrant Directories rather than my development machines?

  9. 9

    How do I execute this find command multiple times throughout many directories with the ampersand '&' command?

  10. 10

    How do I give files and directories created by FTP the correct permissions for Apache to read and write them?

  11. 11

    How do I delete all empty directories in a directory from the command line?

  12. 12

    How do you use UIView with properties or variables inherited from ViewController?

  13. 13

    How do I use OR with if statements in regards to strings

  14. 14

    How do i use Blazor components in the code?

  15. 15

    Python: How do i use itertools?

  16. 16

    How do I use runit with zookeeper

  17. 17

    How do I use Firefox cookies with Wget?

  18. 18

    How do I use the GeometryConstraint class?

  19. 19

    How do I make use of rotation matrices?

  20. 20

    How do I configure ActiveJob to use Resque?

  21. 21

    How do i use SetPixel on a new Bitmap?

  22. 22

    How do i get cURL to use https

  23. 23

    How do I use "<<" with my own struct?

  24. 24

    What is fileAPI ? How do I use it with angular?

  25. 25

    How do I open and use phpmyadmin?

  26. 26

    How do I configure Docker to use ZFS?

  27. 27

    How do I use the latest GCC on Ubuntu?

  28. 28

    How do I use man pages to learn how to use commands?

  29. 29

    How do I communicate variables between methods in Python?

뜨겁다태그

보관