PHP rewrite URL

Source: Internet
Author: User

1. Locate the httpd.conf file under Conf in the Apache installation directory to open the file modification
LoadModule Rewrite_module modules/mod_rewrite.so This line of code, he has a # number in front of it, the # is erased
2. Still the file, open, find
<directory/>
Options followsymlinks execcgi Indexes

AllowOverride None

Order Deny,allow

Deny from all

Satisfy All

</Directory>
This node, change none to all. 3. Restart Apache Service
4. The most critical point is to create the. htaccess file in your project directory, the file has no name, it looks like the suffix name only
The specific creation method can not be created directly, create a TXT file (the other line), and then save the question, change the name to. htaccess, and select all the files, after the creation, it is necessary to make rules. Write the code in the file:
<ifmodule mod_rewrite.c> rewriteengine on//on for open, off for off
Rewriterule ([A-za-z]{1,})-([0-9]{1,}). html$ index.php?action=$1&id=$2 </IfModule>
([A-za-z]{1,})-([0-9]{1,}). html$ is the rule, the index.php?action=$1&id=$2 is the format to be replaced, the value that represents the first parenthesis match, and the second one, and so on!!
5. Create a PHP file (this file will, of course, be created in the project where you put the. htaccess file)
<?php
echo "Your action:". $_get[' action '); echo "Your ID:". $_get[' id ');
Then you access in the browser address bar: http://localhost/text/a-1.html, this address is equivalent to your visit to http://localhost/text/index.php?action=a&id=1. Do you think this is more beautiful?
The result of the visit is your action:a your id:1

PHP rewrite URL

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.