Home >Operation and Maintenance >Linux Operation and Maintenance >Introduction to the usage of .htaccess pseudo-static

Introduction to the usage of .htaccess pseudo-static

PHP中文网
PHP中文网Original
2017-06-20 13:33:121967browse

Apache主机一般支持.htaccess伪静态,即可以实现绑定域名到子目录、一个空间多个站点。

应用举例:绑定htaccess.800m.net到htaccess目录

根目录下.htaccess内容

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# 绑定htaccess.800m.net到子目录htaccess
RewriteCond %{HTTP_HOST} ^htaccess\.800m\.net$ [NC]
RewriteCond %{REQUEST_URI} !^/htaccess/
RewriteRule ^(.*)$ htaccess/$1?Rewrite [L,QSA]
#可以绑定多个,只需重复上三行代码并更改一下域名、目录名就行了
</IfModule>

 即使HTTP_HOST中的“.”不加反斜杠,也能够实现绑定htaccess.800m.net,因为“.”可以匹配任意一个字符。

htaccess目录下的.htaccess内容

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#只许绑定的域名访问,其他域名301跳转
RewriteCond %{HTTP_HOST} !^htaccess\.800m\.net$ [NC]
RewriteRule (.*) $1 [L,R=301]
#对绑定目录下htaccess目录的处理
RewriteCond %{REQUEST_URI} ^\/htaccess\/ [NC]
RewriteCond %{QUERY_STRING} !^(.*)?Rewrite
#htaccess.800m.net/htaccess实际上访问htaccess.800m.net/htaccess/htaccess
RewriteRule ^(.*)$ /%{REQUEST_URI}/%{REQUEST_URI}/$1?Rewrite [L,QSA]
</IfModule>

 当然,如果对绑定子目录的要求不高的话,子目录下就不需要建立.htaccess文件了。

The above is the detailed content of Introduction to the usage of .htaccess pseudo-static. For more information, please follow other related articles on the PHP Chinese website!

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