Use. htaccess to implement pseudo-static methods

Source: Internet
Author: User
Tags php and

First, configure the server to start the rewrite module.
Open the configuration file httpd. conf of Apache.
Remove # before # LoadModule rewrite_module modules/mod_rewrite.
Restart Apache after saving


Write rewrite rules
For example, the code in test. php is

The code is as follows: Copy code
<? Php
$ Id = $ _ GET ["id"];
Echo $ id;
?>

The function is to accept the id parameter in the URL and display it on the page.
First, use notepad (if not, use editplus) to create a document and save it as. htaccess. Write the following code in it:

The code is as follows: Copy code
. <IFMODULE mod_rewrite.c>
. RewriteEngine On
. RewriteBase/
. RewriteRule ^ t _ (. * example .html $ test. php? Id = $1 [L]
. </IFMODULE>

For more information, see The apache manual. Download apache2.2 manual
Line 10 ^ t _ (. * pai.html $ describes the URL you entered, test. php? Id = $1 the actual address to access
For example, if you enter localhost/mytest/t_1.html in the browser (assuming that both your test. php and. htaccess files are in the mytest folder on your server), 1 is output in the browser,
If the input is localhost/mytest/t_sophp.html, the browser outputs sophp
The first address actually accesses localhost/mytest/test. php? Id = 1
The second actual access is localhost/mytest/test. php? Id = sophp

After the rule is rewritten, you can change the URL link of the previous parameter to the rule style you modified.
If the purchased space supports rewriting, you only need to upload the. htaccess file to the root directory.

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.