欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

apache+codeigniter 通过.htcaccess做动态二级域名解析

程序员文章站 2022-05-25 21:09:57
复制代码 代码如下: authname "yousite website coming soon..." //如果你想给你的网站加个权限访问 authtype basic...
复制代码 代码如下:

authname "yousite website coming soon..." //如果你想给你的网站加个权限访问
authtype basic
authuserfile d:/xxx/.htpasswd #如果你想设置密码访问 如何生成.htpasswd可以访问 http://www.htaccesstools.com/htpasswd-generator/
#authgroupfile /dev/null
require valid-user

<ifmodule mod_rewrite.c>
rewriteengine on
rewritebase /

#removes access to the system folder by users.
#additionally this will allow you to create a system.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
rewritecond %{request_uri} ^system.*
rewriterule ^(.*)$ /index.php?/$1 [l]

#when your application folder isn't in the system folder
#this snippet prevents user access to the application folder
#submitted by: fabdrol
#rename 'application' to your applications folder name.
rewritecond %{request_uri} ^application.*
rewriterule ^(.*)$ /index.php?/$1 [l]


<ifmodule mod_proxy.c>
# redirect to boutique (with any trailing path)
rewritecond %{http_host} !^www. [nc]
rewritecond %{http_host} ^([^.]+).yousite.com(.*)$ [nc]
rewriterule ^(.*)$ http://www.yousite.com/boutique/$1$2 [p,l]
</ifmodule>

<ifmodule !mod_proxy.c>
# redirect to boutique (with any trailing path)
rewritecond %{http_host} !^www. [nc]
rewritecond %{http_host} ^([^.]+).yousite.com(.*)$ [nc]
rewriterule ^(.*)$ http://www.yousite.com/boutique/%1/$1 [r=301,l]
</ifmodule>

## otherwise, force www;
rewritecond %{http_host} ^yousite.com$ [nc]
rewriterule ^(.*)$ http://www.yousite.com/$1 [r=301,l]

#checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
rewritecond %{request_filename} !-f
rewritecond %{request_filename} !-d
rewriterule ^(.*)$ index.php/$1 [l]
</ifmodule>

<ifmodule !mod_rewrite.c>
# if we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# submitted by: elliothaughin

errordocument 404 /index.php
</ifmodule>

出处:cnblogs 微博:@草根小胡