溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶(hù)服務(wù)條款》

如何在apache中利用.htcaccess文件做動(dòng)態(tài)二級(jí)域名解析

發(fā)布時(shí)間:2021-03-02 16:40:05 來(lái)源:億速云 閱讀:188 作者:Leah 欄目:開(kāi)發(fā)技術(shù)

本篇文章為大家展示了如何在apache中利用.htcaccess文件做動(dòng)態(tài)二級(jí)域名解析,內(nèi)容簡(jiǎn)明扼要并且容易理解,絕對(duì)能使你眼前一亮,通過(guò)這篇文章的詳細(xì)介紹希望你能有所收獲。

代碼如下:


AuthName "yousite Website Coming Soon..." //如果你想給你的網(wǎng)站加個(gè)權(quán)限訪問(wèn)
AuthType Basic
AuthUserFile D:/xxx/.htpasswd #如果你想設(shè)置密碼訪問(wèn) 如何生成.htpasswd可以訪問(wèn) 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>

上述內(nèi)容就是如何在apache中利用.htcaccess文件做動(dòng)態(tài)二級(jí)域名解析,你們學(xué)到知識(shí)或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識(shí)儲(chǔ)備,歡迎關(guān)注億速云行業(yè)資訊頻道。

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI