Home  >  Article  >  Backend Development  >  Introduction to PHP pseudo-static URL REWRITE rewriting rules

Introduction to PHP pseudo-static URL REWRITE rewriting rules

WBOY
WBOYOriginal
2016-07-25 08:59:431006browse
  1. Options FollowSymLinks
  2. AllowOverride None
Copy code

Change to

  1. Options FollowSymLinks
  2. AllowOverride All
Copy code

2. Create .htaccess file The three methods all first create a text file htaccess.txt (of course, you can choose the name of this text file casually), and then there are three ways to rename this file: (1) Open with Notepad, click File – Save As, enter ".htaccess" in the file name window, pay attention to the entire green part, which includes English quotes, and then click Save. (2) Enter the cmd command window, use cd to switch to the folder where the htaccess.txt file was just created, then enter the command: rename htaccess.txt .htaccess, and then click the Enter key on the keyboard. (3) Connect the folder where htaccess.txt is located through ftp, and rename it through ftp software. (4) .htaccess can also be created through third-party editors such as Dreamweaver.

3. Learning rewrite rules Create a new .htaccess file:

  1. RewriteEngine on #rewriteengine is the rewrite engine switch on is on off is off
  2. RewriteRule ([0-9]{1,})$ index.php?id=$1
Copy code

RewriteRule is a rewriting rule that supports regular expressions. The above ([0-9]{1,}) refers to the number, and $ is the end mark, indicating that it ends with a number! Pseudo-static page rules:

  1. RewriteEngine on
  2. RewriteRule ([a-zA-Z]{1,})-([0-9]{1,}).html$ index.php?action=$1&id=$2
Copy code

([a-zA-Z]{1,})-([0-9]{1,}).html$ is the rule, index.php?action=$1&id=$2 is the requirement In the replacement format, $1 represents the value matched by the first bracket, $2 represents the second one, and so on! !

index.php for testing

  1. echo 'Your Action is:' . $_GET['action'];
  2. echo '
  3. ';
  4. echo 'Your ID is:' . $_GET['id' ];
  5. ?>
Copy the code

and enter it in the browser: http://jbxue.com/view-12.html The output is: Your Action is: view Your ID is: 12

That’s it, I hope it helps everyone.



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn