PHP pseudo-static configuration

Source: Internet
Author: User
Tags ord

Configuring virtual hosts and pseudo-static

1. Open the Apache rewrite module

LoadModule Rewrite_module modules/mod_rewrite.so

2. Turn on the virtual host feature

# Virtual Hosts
Include conf/extra/httpd-vhosts.conf

3. Modify the Conf/extra/httpd-vhosts.conf file

<virtualhost *:80>

DocumentRoot "F:/wamp/www/teacher" specifies access to the directory
ServerName www.baidu.com Specifies the domain name that is allowed to access
<directory "F:/wamp/www/teacher" > Set this directory

Deny from all prohibits anyone from accessing, not writing can be accessed, because if this directory is not set up, will inherit his parent directory to permissions, if the parent directory is forbidden to access, you can write in this directory can be allowed from all the directory is accessible, does not inherit the permissions of the parent directory

Options None does not allow the server to display a list of files in the directory, allowing it to be changed to options indexes

DirectoryIndex abc.html 123.html Configuration directory to specify the first page, the default is index, specify the first select Abc.html, if not display 123.html

ErrorDocument 404/404.html Specifies the page to be displayed after an error, ErrorDocument followed by an HTTP status code, and when this state is encountered, the page specified later is executed

AllowOverride all allows to read rules in the. htaccess file of the corresponding directory

Configure the rewrite rule below

Rewriteengine on turn on re-function (be sure to check whether the Mod_rewrite.so module is enabled)

Rewriterule a.html b.php When accessing the a.html page is actually a visit to b.php

Rewriterule News/id/(\d+). HTML news.php?id=$1 for a wide range of uses, you can use regular to match news/id/100.html, which are all in the direction of the news.php, the received parameter is the previous matching value

</Directory>
</VirtualHost>

How 4.htaccess files are written

In the case where you do not have permission to modify the httpd-vhosts.conf file, you can use the. htaccess file to do directory permissions if the. htaccess doesn't work, just see if the httpd-vhosts.conf file is open allowoverride All

<ifmodule rewrite_module> #如果加载了rewrite_module模块

These rules are written in the same way as the rules in the httpd-vhosts.conf file

Rewriteengine on

Rewriterule News/id/(\d+). HTML news.php?id=$1

You can write more than one rule

</IfModule>

5. Do anti-theft chain

<ifmodule rewrite_module>
Rewriteengine on
Rewritecond%{http_referer}!^http://(www\.)? Xuni.com (/)?. *[NC]     REWRITERULE.∗\.(GIF|JPG|JPEG|m| n)

http://www.xuni.com/warning.xjpg [R,NC]
</IfModule>

6. Add the domain name to the local 127.0.0.1 in the C:\WINDOWS\SYSTEM32\DRIVERS\ETC host file www.xuni.com

Note: When configured, turn on localhost discovery Tip 403 error because the virtual host feature is turned on (second step), In the httpd-vhosts.conf file by default added a few rules, because the use of the WAMP environment, the documentroot is not Wamp specified root directory, causing localhost to navigate to the wrong directory, which is caused by localhost can not access 403 reasons, as long as the default The rules are modified under

<virtualhost *:80>
ServerAdmin [email protected]
DocumentRoot "F:/wamp/www" #访问的根目录
ServerName localhost #允许访问的域名
Errorlog "Logs/dummy-host2.example.com-error.log"
Customlog "Logs/dummy-host2.example.com-access.log" common
</VirtualHost>

Then add the rules you need later

PHP pseudo-static configuration

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.