一.开启重写模块
二.找到搜索到httpd.conf:AllowOverride
方法一:直接在httpd.conf文件下改 (不推荐,这样导致服务器上的所有网站都开启了重写,每个网站访问时都会扫描.htaccess文件)
<Directory />
AllowOverride none (改成 AllowOverride all)
Require all granted
</Directory>
方法二:直接添加在httpd.conf文件底部
<Directory "D:/wamp/www"(网站路径)>
Options FollowSymLinks
AllowOverride all
Order deny,allow
</Directory>
方法三:直接在虚拟主机里面添加目录权限(httpd-vhosts.conf或者httpd.conf)
<VirtualHost *:80>
DocumentRoot "D:/wamp/www/test"
ServerName test.com
ServerAlias test.com
<Directory "D:/wamp/www"(网站路径)>
Options FollowSymLinks
AllowOverride all
Order deny,allow
</Directory>
</VirtualHost>
Options指令-------目录的访问特性
option none 禁止对目录的所有操作
option all 允许对目录的所有操作,ALL---所有操作
option ExecCGI 对该目录,可以执行cgi脚本
option Indexes 允许访问该目录(而该目录没有index.html)时,返回目录下的文件列表
option FollowSymLinks 只允许对目录的FollowSymLinks操作
AllowOverride指令
None 不读取.htaccess
all all----允许.htaccess所有指令,缺省是all
Limit .htaccess函盖具体限定的主机(allow,deny)
AuthConfig .htaccess函盖跟认证有关指令(AuthType,AuthName)
Order 指令
为指定排序deny或者是allow,用','隔开
Deny from XXX
Allow from XXXX
参数3可以是IP(可以使某个范围或者是特定一个),域名,all
Allow from 10.1.2.3
Allow from 192.168.1.104 192.168.1.205
Allow from apache.org
三.在根目录下添加.htaccess文件
内容形如:
RewriteEngine on
# 统一网址,去掉www。如果你想保留www,自己在第二行添加
# RewriteCond的'%'是后向引用 [NC]代表不区分大小写
# RewriteRule的'$'是后向引用 [L,R=301] L表明当前规则是最后一条规则,停止分析以后规则的重写 R重定向(301重定向是永久的重定向/302重定向是暂时的重定向)
#RewriteCond ^%{HTTP_HOST} ^test.com [NC]
RewriteCond %{HTTP_HOST} ^test.com [NC]
RewriteRule ^(.*)$ http://www.test.com/$1 [L,R=301]
#RewriteCond %{HTTP_HOST} test.com [NC]
#RewriteRule (.*) http://www.baidu.com/$1 [R=301,L]
RewriteRule ^index.html$ index.php
二.找到搜索到httpd.conf:AllowOverride
方法一:直接在httpd.conf文件下改 (不推荐,这样导致服务器上的所有网站都开启了重写,每个网站访问时都会扫描.htaccess文件)
<Directory />
AllowOverride none (改成 AllowOverride all)
Require all granted
</Directory>
方法二:直接添加在httpd.conf文件底部
<Directory "D:/wamp/www"(网站路径)>
Options FollowSymLinks
AllowOverride all
Order deny,allow
</Directory>
方法三:直接在虚拟主机里面添加目录权限(httpd-vhosts.conf或者httpd.conf)
<VirtualHost *:80>
DocumentRoot "D:/wamp/www/test"
ServerName test.com
ServerAlias test.com
<Directory "D:/wamp/www"(网站路径)>
Options FollowSymLinks
AllowOverride all
Order deny,allow
</Directory>
</VirtualHost>
Options指令-------目录的访问特性
option none 禁止对目录的所有操作
option all 允许对目录的所有操作,ALL---所有操作
option ExecCGI 对该目录,可以执行cgi脚本
option Indexes 允许访问该目录(而该目录没有index.html)时,返回目录下的文件列表
option FollowSymLinks 只允许对目录的FollowSymLinks操作
AllowOverride指令
None 不读取.htaccess
all all----允许.htaccess所有指令,缺省是all
Limit .htaccess函盖具体限定的主机(allow,deny)
AuthConfig .htaccess函盖跟认证有关指令(AuthType,AuthName)
Order 指令
为指定排序deny或者是allow,用','隔开
Deny from XXX
Allow from XXXX
参数3可以是IP(可以使某个范围或者是特定一个),域名,all
Allow from 10.1.2.3
Allow from 192.168.1.104 192.168.1.205
Allow from apache.org
三.在根目录下添加.htaccess文件
内容形如:
RewriteEngine on
# 统一网址,去掉www。如果你想保留www,自己在第二行添加
# RewriteCond的'%'是后向引用 [NC]代表不区分大小写
# RewriteRule的'$'是后向引用 [L,R=301] L表明当前规则是最后一条规则,停止分析以后规则的重写 R重定向(301重定向是永久的重定向/302重定向是暂时的重定向)
#RewriteCond ^%{HTTP_HOST} ^test.com [NC]
RewriteCond %{HTTP_HOST} ^test.com [NC]
RewriteRule ^(.*)$ http://www.test.com/$1 [L,R=301]
#RewriteCond %{HTTP_HOST} test.com [NC]
#RewriteRule (.*) http://www.baidu.com/$1 [R=301,L]
RewriteRule ^index.html$ index.php