久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

.htaccess 將子域重寫(xiě)到目錄并將子域保留在 url 中

.htaccess rewrite subdomain to directory and keep subdomain in url(.htaccess 將子域重寫(xiě)到目錄并將子域保留在 url 中)
本文介紹了.htaccess 將子域重寫(xiě)到目錄并將子域保留在 url 中的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

我需要使用 .htaccess 將子域重寫(xiě)為子目錄,但將子域保留在 url 中,如下所示:

I need to rewrite a subdomain to a subdirectory using .htaccess but keep the subdomain in the url like this:

瀏覽器中訪問(wèn)的 url:sub1.domain.com

Visited url in browser: sub1.domain.com

提供的網(wǎng)址:sub.domain.com/sub1/

我嘗試了以下

RewriteCond %{HTTP_HOST} ^subdomain.domain.com
RewriteRule ^(.*)$ http://subdomain.domain.com/subdomain/$1 [L,NC,QSA]

但這會(huì)導(dǎo)致無(wú)限循環(huán).我知道通過(guò) php 執(zhí)行此操作會(huì)更容易,但是使用 .htaccess 是否有任何解決方案?

but this leads to an endless loop. I know that it would be easier to do this by php but is there any solution for this with using .htaccess?

推薦答案

您可以在文檔根目錄中使用此規(guī)則:

You can use this rule in document root:

RewriteCond %{HTTP_HOST} ^subdomain.domain.com$ [NC]
RewriteRule ^((?!sub1/).*)$ /sub1/$1 [L,NC]

說(shuō)明:

  • NC:忽略大小寫(xiě)
  • L:最后一條規(guī)則
  • RewriteCond %{HTTP_HOST} 行確保規(guī)則只對(duì) subdomain 執(zhí)行
  • (?!sub1/) 是否定前瞻表達(dá)式,表示請(qǐng)求的意思不是以 /sub1/
  • 開(kāi)頭
  • RewriteRule ^((?!sub1/).*)$/sub1/$1 [L,NC] 將當(dāng)前路徑重寫(xiě)為 /sub1/
  • NC: Ignore case
  • L: Last rule
  • RewriteCond %{HTTP_HOST} line makes sure that rule only executes for subdomain
  • (?!sub1/) is negative lookahead expression that means of request is not starting with /sub1/
  • RewriteRule ^((?!sub1/).*)$ /sub1/$1 [L,NC] rewrites current path to /sub1/<uri>
  • Apache mod_rewrite 介紹
  • Apache mod_rewrite 技術(shù)細(xì)節(jié)

這篇關(guān)于.htaccess 將子域重寫(xiě)到目錄并將子域保留在 url 中的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Action View Helper in Zend - Work around?(Zend 中的動(dòng)作視圖助手 - 解決方法?)
Is this a good way to match URI to class/method in PHP for MVC(這是將 URI 與 PHP 中用于 MVC 的類(lèi)/方法匹配的好方法嗎)
Where do I save partial (views) in Zend Framework, to be accessible for all Views in my App?(我在哪里保存 Zend Framework 中的部分(視圖),以便我的應(yīng)用程序中的所有視圖都可以訪問(wèn)?) - IT屋-程序員軟件開(kāi)發(fā)技術(shù)
Having a single entry point to a website. Bad? Good? Non-issue?(有一個(gè)網(wǎng)站的單一入口點(diǎn).壞的?好的?沒(méi)問(wèn)題?)
Is MVC + Service Layer common in zend or PHP?(MVC + 服務(wù)層在 Zend 或 PHP 中常見(jiàn)嗎?)
Hello World example in MVC approach to PHP(PHP MVC 方法中的 Hello World 示例)
主站蜘蛛池模板: 亚洲精品欧洲 | 国产男女视频网站 | 国产伦一区二区三区 | 男女下面一进一出网站 | 91久久国产综合久久91精品网站 | 黑人巨大精品欧美一区二区一视频 | 精品久久久久久久久亚洲 | 色爱综合网 | 亚洲男人天堂av | 秋霞性生活| 在线观看国产视频 | 国产一区二区在线免费播放 | 成年人黄色小视频 | 成人在线中文字幕 | 日韩一区二区三区在线视频 | 久久久国产一区二区三区 | 天天拍夜夜爽 | 国产精品久久久久久久久久免费看 | 欧美精品1区2区 | 亚洲区一区二 | 亚洲一区二区三区久久久 | 精品视频一区二区 | 亚洲免费在线观看av | 久久人体 | 最新超碰 | 欧美久久天堂 | av免费网站在线观看 | 亚洲成人中文字幕 | 欧美国产中文字幕 | 日本在线小视频 | 日韩av一区二区在线观看 | 精品国产乱码久久久久久a丨 | 久久婷婷色 | 一区二区三区四区免费观看 | 日韩欧美在线观看 | 国产精品久久视频 | 日韩精品久久一区二区三区 | 日韩欧美一级精品久久 | 91高清免费观看 | 日本久久久影视 | 久久精品一区 |