第一步:修改httpd.conf
1)
用文本编辑器打开Apache安装目录/etc/httpd/conf\httpd.conf,找到“#LoadModulerewrite_module modules/mod_rewrite.so”这行,去掉前面的“#”;继续查找“AllowOverride None”,修改为“AllowOverride All”,然后,重启Apache即可。
2)添加二级域名与目录的对应关系
- NameVirtualHost *:80
- <VirtualHost *:80>
- ServerName bs.gudianxiaoshuo.com //一开始这里写错了 写成了gudianxiaoshuo.com/bs 所以二级域名一直登陆不了
- DocumentRoot /var/www/html/gudianxiaoshuo
- </VirtualHost>
3) 同样,我们在httpd.conf文件最后输入以下语句:
RewriteEngine on
RewriteMap lowercase int:tolower
RewriteMap vhost txt:/etc/httpd/vhost.map
RewriteCond ${lowercase:%{SERVER_NAME}} ^(.+)$
RewriteCond ${vhost:%1} ^(/.*)$
RewriteRule ^/(.*)$ %1/$1
第二步:
之后在/etc/httpd(即Apache安装目录)下新建一个vhost.map,用文本编辑器来绑定,极其简单,我的是这样写的:
bs.gudianxiaoshuo.com /var/www/html/gudianxiaoshuo
home.nvdchina.com /var/www/html/home
potplayer.nvdchina.com /var/www/html/potplayer
我们可以随意把二级域名与目录绑定,保存就行,并且 不用 重启Apache,非常方便
我使用了网上的提供的前两步方法后,还不能实现 跳出DNS错误,估计是需要添加DNS解析
第三步: 二级域名解析
我是使用dnspod.cn上的域名解析的
二级域名解析如下
经过这几步后,可以正常访问二级域名了
但是我在访问二级域名下的文件夹时出现
- Internal Server Error
- The server encountered an internal error or misconfiguration and was unable to complete your request.
- Please contact the server administrator,root@localhost and inform them of the time the error occurred,and anything you might have done that may have caused the error.
- More information about this error may be available in the server error log.
首页正常出现APACH信息,但是下面的文件夹和子文件访问出错
我的文件夹是Demo
查了许多资料,有的说linux下文件权限设置755才可以 但是我755 777都试过还是不行
奇怪的是访问bs文件夹却可以
后来我又重新建了文件夹也可以,莫非是大小写的原因?
我在浏览器上输入的是Demo但是浏览器往往都自动改变成demo了,于是我将我的文件夹都改成小写后,就可以了?
以前没遇到这样的问题,莫非是二级域名下面的文件夹和文件都要区分大小写?又因为浏览器自动小写,所以下面的文件和文件夹都要小写才可以么?