A method for implementing a pseudo static URL using. htaccess in the Apache server _linux

Source: Internet
Author: User
Tags php and

Many friends may be the space is the virtual host, they do not have the authority to manage Apache httpd.conf files, naturally it is not likely to write static rules on this, we can let the host to open support. htaccess method so that you can write yourself.

First configure the server startup rewrite module
Open the Apache configuration file httpd.conf.
Remove the # #loadmodule Rewrite_module modules/mod_rewrite front.
Restart Apache after saving


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

<?php
$id =$_get["id"];
echo $id;
? > 

The function is to accept the ID parameter in the URL and display it on the page.
First create a new document with Notepad (if not, and then save it as. htaccess, write the following code in the EditPlus)

. <ifmodule mod_rewrite.c>
. Rewriteengine on
. Rewritebase/
. Rewriterule ^t_ (. *). html$ test.php?id=$1 [L]
.</ifmodule> 

For a specific explanation, you can view the Apache manual. Download apache2.2 Manual
Line 4th ^t_ (. *). html$ describes the URL address you entered, test.php?id=$1 the address it actually wants to access
For example, when you enter in a browser (assuming that your test.php and. htaccess files are in the MyTest folder of your server) localhost/mytest/t_1.html will output 1 in the browser.
If entered as localhost/mytest/t_sophp.html, the browser output sophp
The first address is actually accessed by localhost/mytest/test.php?id=1
The second actual access is localhost/mytest/test.php?id=sophp

After you have overridden the rule, it is successful to change the URL link in your Web page that was used to pass parameters to your modified rule style.
If the space you buy is supported by rewriting, just 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.