0,以Windows 的 wamp为例:
一,配置host: C:\Windows\System32\drivers\etc\hosts
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
0.0.0.0 account.jetbrains.com # phpstorm的 lanyu【百度一下 lanyu】#webserver_study_ci_or_laravel
127.0.0.1 www.ci_test.net
127.0.0.1 www.la_test.cc
二,Apache配置:
D:\wamp64\bin\apache\apache2.4.23\conf\extra\httpd-vhosts.conf 修改前 【可以自己选择文件夹,而不是通过域名】
D:\wamp64\bin\apache\apache2.4.23\conf\extra\httpd-vhosts.conf 修改后
# Virtual Hosts
// 1,配置的是CI框架,本机访问
<VirtualHost *:80>
ServerName www.ci_test.net
DocumentRoot D:/wamp64/www/ci_webserver/ci_test
<Directory "D:/wamp64/www/ci_webserver/ci_test">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
// 2,配置的是laravel框架,本机访问,注意 【public】为根目录
<VirtualHost *:80>
ServerName www.la_test.cc
DocumentRoot D:/wamp64/www/laravel5.5/sudo/public
<Directory "D:/wamp64/www/laravel5.5/sudo/public">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
三,如果CI框架 要求 重写了路由,又该怎么弄【like: CI框架默认的index.php去除】
&1,去除CI框架 index.php 的方法 :
方案原址:https://blog.csdn.net/jacker_i/article/details/52859182
一、apache
1.打开apache的配置文件,D:\wamp64\bin\apache\apache2.4.23\conf\httpd.conf :
1
LoadModule rewrite_module modules/mod_rewrite.so
把该行前的#去掉。
搜索 AllowOverride None(配置文件中有多处),看注释信息,将相关.htaccess的该行信息改为:
1
AllowOverride All
二、CI框架
2.在CI的根目录下,在system的同级目录下,建立.htaccess文件,写入如下内容:
1
2
3
4
5
RewriteEngine
on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
如果文件不是在www的根目录下,例如我的是:
1
http:
//localhost/CI/index.php/
第三行需要改写为
1
RewriteRule ^(.*)$ /CI/index.php/$1 [L]
另外,我的index.php的同级目录下还有 assets 【存放 js css images 等 】文件夹,这些需要过滤除去,第二行需要改写为:
1
RewriteCond $1 !^(index\.php|images|assets|robots\.txt
1,根目录system同级目录 .htaccess 【没有,新建】 / global【存放 js css images 等 】文件夹 。我的.htaccess 是:
RewriteEngine onRewriteCond $1 !^(index\.php|global|robots\.txt)
RewriteRule ^(.*)$ index.php?/$1 [L]
如果不在根目录下:
RewriteEngine on RewriteCond $1 !^(index\.php|images|robots\.txt) RewriteRule ^(.*)$ /目录/index.php/$1 [L]
3.将CI中配置文件(application/config/config.php)中
1
$config[
'index_page'
] =
"index.php"
;
改成
1
$config[
'index_page'
] =
""
;
重启apache,完成。
其他方法 :注意:还可以参考 apache / nginx 修改CI的 index.php :https://blog.csdn.net/ikscher/article/details/39959005
&2,原来我为了重写路由,修改 Apache的一些配置:
1,配置一,D:\wamp64\bin\apache\apache2.4.23\conf\httpd.conf 全站搜索,使用 notepad++ 软件
我的默认:
# Virtual hosts
Include conf/extra/httpd-vhosts.conf原始:
# Virtual hosts
# Include conf/extra/httpd-vhosts.conf
2,配置二:D:\wamp64\bin\apache\apache2.4.23\conf\httpd.conf
修改<Directory> 全站搜索,使用 notepad++ 软件
# "c:/Apache24/cgi-bin" should be changed to whatever your ScriptAliased
# CGI directory exists, if you have that configured.
#
<Directory "${INSTALL_DIR}/cgi-bin">
AllowOverride All # 原来 All 为 None
Options None
Require all granted
</Directory>
3,配置三:D:\wamp64\bin\apache\apache2.4.23\conf\httpd.conf
LoadModule autoindex_module modules/mod_autoindex.so 与
Include conf/extra/httpd-autoindex.conf 的 # 去除
四,多域名与文件夹访问并存【有域名的访问域名,没有的访问 localhost下面的文件夹】
D:\wamp64\bin\apache\apache2.4.23\conf\extra\httpd-vhosts.conf
# Virtual Hosts
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot “D:\wamp\www”
ServerName localhost
ServerAlias localhost
ErrorLog “logs/dummy-host.localhost-error.log”
CustomLog “logs/dummy-host.localhost-access.log” common
</VirtualHost>// 下面配置 多站点
<VirtualHost *:80>
ServerName www.la_test.cc
DocumentRoot D:/wamp64/www/laravel5.5/sudo/public
<Directory "D:/wamp64/www/laravel5.5/sudo/public">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost><VirtualHost *:80>
ServerName www.ci_test.net
DocumentRoot D:/wamp64/www/ci_webserver/ci_test
<Directory "D:/wamp64/www/ci_webserver/ci_test">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
备用方法:(其他方法不成功时,使用)
D:\wamp64\bin\apache\apache2.4.23\conf\httpd.conf
找到DirectoryIndex,删除默认设置
<IfModule dir_module>
DirectoryIndex index.php index.php3 index.html index.htm
</IfModule>改为
<IfModule dir_module>
DirectoryIndex
</IfModule>重启wamp服务,输入localhost 会出现 文件夹。
五,wampserver 允许外网访问配置:
D:\wamp64\bin\apache\apache2.4.23\conf\httpd.conf
网址:https://blog.csdn.net/keepfriend/article/details/76360276
用编辑器打开http.conf
大概244行:
改为
<Directory />
AllowOverride none
Require all granted
</Directory>大概288行:
改为
# onlineoffline tag - don't remove
Require all granted大概387行:
改为
<Directory "${INSTALL_DIR}/cgi-bin">
# AllowOverride None
Options None
Require all granted
</Directory>2.打开httpd-vhosts.conf 将Directory里面内容更换为以下内容
<Directory "d:/wamp64/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
Require all granted
</Directory>