本经验分享是在假定已启用多站点功能的情况下进行配置操作,需要特别注意的地方已用颜色标识,与实现伪静态功能直接相关。 一、找到并打开D:\apache\conf下httpd文件,查找到LoadModule rewrite_module ...

        本经验分享是在假定已启用多站点功能的情况下进行配置操作,需要特别注意的地方已用颜色标识,与实现伪静态功能直接相关。

        一、找到并打开D:\apache\conf下httpd文件,查找到LoadModule rewrite_module modules/mod_rewrite.so并去掉前面的#,保存并退出。

        二、配置服务器中多个站点中的某一个特定网站,如www.XXX.com,其他依次类推:

        打开D:\apache\conf\extra\httpd-ssl(针对https协议443端口,确保已启用该文件)或httpd-vhosts(针对http协议80端口,确保已启用该文件)文件,新增或修改如下(本文仅针对https协议443端口进行示例):

#配置www.XXX.com网站 <VirtualHost *:443> DocumentRoot "d:/web003/XXXcom/" ServerName XXX.com ServerAlias www.XXX.com SSLEngine on SSLCertificateFile "d:/apache/cert/XXXcom/XXX.com.crt" SSLCertificateKeyFile "d:/apache/cert/XXXcom/XXX.com.key" SSLCertificateChainFile "d:/apache/cert/XXXcom/root_bundle.crt" DirectoryIndex index.php index.html <Directory "d:/web003/XXXcom"> # 表示允许选择使用符号链接功能 Options FollowSymLinks # 允许调用该网站根目录下.htaccess文件以实现伪静态功能 AllowOverride All <RequireAll> Require all granted # 屏蔽某一特定IP Require not ip 162.55.85.223 20.211.163.226 148.251.190.243 64.62.252.162 154.54.249.207 20.213.249.172 # 屏蔽某一特定IP段 Require not ip 123.149 171.8 125.41 125.46 61.52 222.137 123.52 1.192 182.119 123.161 221.15 123.160 27.115.124 185.191.171 51.222.253 180.163.220 216.244.66 113.24.224 </RequireAll> </Directory> CustomLog "logs/XXXcom.log" combined </VirtualHost>

        三、在您的网站根目录下打开或新建.htaccess文件,里面配置代码如下,本处针对某一特定系统配置,不同的系统可能会有细微差别,请向程序开发商索取伪静态配置规则:

<IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{HTTP_HOST} ^xxx.com$ [NC] RewriteRule ^(.*)$ https://www.xxx.com/$1 [R=301,L] RewriteCond %{SERVER_PORT} 80  RewriteRule ^(.*)$ https://%{SERVER_NAME}/$1 [R,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^.*$ index.php?$0 </IfModule>

        四、开启网站伪静态功能,查看网站伪静态是否正常。

        此外,您也可以直接把第三步的伪静态规则写进第二步,即D:\apache\conf\extra\httpd-ssl(针对https协议443端口)或httpd-vhosts(针对http协议80端口)文件中,不用再调用网站目录下的.htaccess文件,即可直接实现伪静态功能,具体如下:

#配置www.XXX.com网站 <VirtualHost *:443> DocumentRoot "d:/web003/XXXcom/" ServerName XXX.com ServerAlias www.XXX.com SSLEngine on SSLCertificateFile "d:/apache/cert/XXXcom/XXX.com.crt" SSLCertificateKeyFile "d:/apache/cert/XXXcom/XXX.com.key" SSLCertificateChainFile "d:/apache/cert/XXXcom/root_bundle.crt" DirectoryIndex index.php index.html <Directory "d:/web003/XXXcom">  RewriteEngine on RewriteCond %{HTTP_HOST} ^xxx.com$ [NC] RewriteRule ^(.*)$ https://www.xxx.com/$1 [R=301,L] RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://%{SERVER_NAME}/$1 [R,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^.*$ index.php?$0 # 表示允许选择使用符号链接功能 Options FollowSymLinks # 禁止调用该网站根目录下.htaccess文件 AllowOverride None <RequireAll> Require all granted # 屏蔽某一特定IP Require not ip 162.55.85.223 20.211.163.226 148.251.190.243 64.62.252.162 154.54.249.207 20.213.249.172 # 屏蔽某一特定IP段 Require not ip 123.149 171.8 125.41 125.46 61.52 222.137 123.52 1.192 182.119 123.161 221.15 123.160 27.115.124 185.191.171 51.222.253 180.163.220 216.244.66 113.24.224 </RequireAll> </Directory> CustomLog "logs/XXXcom.log" combined </VirtualHost>