簡體   English   中英

將所有文件夾重定向到htaccess子域

[英]Redirect all folders to subdomains htaccess

我試圖將每個文件夾從domain.com重定向到它的子域。

例子:

domain.com/a -> a.domain.com
domain.com/b -> b.domain.com
domain.com/about -> about.domain.com

因此,基本上,每個文件夾都重定向到其子域。 對於第一個示例,文件夾a包含index.html 當我瀏覽到domain.com/a時,應將URL重定向到a.domain.com,但使用a文件夾中的index.html文件。

我當前的htaccess如下所示:

RewriteEngine on
RewriteBase /


RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

RewriteCond %{HTTP_HOST} !^www\.domain\.com$
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com$
RewriteCond %{REQUEST_URI} !^/%1/


RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /%1/$1

RewriteRule ^(/)?$ %1/index.html [L]

什么工作現在,如果我瀏覽到test.domain.com,它的工作,它采取從測試文件夾中的index.html文件。 如果我轉到domain.com/test,它仍在工作,但是我想禁用它。 我也想將domain.com/test重定向到test.domain.com,但仍使用test文件夾中的index.html文件。

htacces文件中的另一件事是將www重定向到非www。

任何建議,將不勝感激。

編輯:忘記提及我嘗試添加此行:

RedirectMatch 301 ^/test/(.*)$ http://test.domain.com/$1

它正在執行從domain.com/test到test.domain.com/index.html的重定向,但是沒有正確加載頁面,我收到一個錯誤(頁面未正確重定向)。

保持類似RedirectMatch 301 ^ {RELATIVE PATH} $ {ABSOLUTE_PATH}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM