我處於用戶可以在子域中創建其博客的情況。將子域通配符重寫爲子目錄
用戶將創建的博客,並輸入他想要像說的地址,
abcd.domain.com
然後我的PHP代碼創建了一個名爲abcd
目錄。
查看博客用戶將鍵入在他的瀏覽器abcd.domain.com
,我想一個.htaccess
代碼將改寫的URL,然後打開domain.com/abcd
裏面的文件,但用戶在瀏覽器的URL應該保持abcd.domain.com
目前我想這個代碼
RewriteCond %{HTTP_HOST} ^test\.domain\.com$
RewriteCond %{REQUEST_URI} !^test/
RewriteRule ^(.*)$ /test/$1 [L,QSA]
但是這給了我404,即使我有test文件夾中的文件test.html
並試圖查看該頁面。
也在這種情況下,我將不得不手動更改.htaccess文件的URL重寫。我想知道的是,如果可以將通配符子域重定向到相應的目錄。
雖然代碼的第一部分解決了測試文件夾的404,但通配符的第二部分不起作用。當我嘗試使用第二個.htaccess代碼重新加載與第一個代碼一起工作的相同url時,我收到錯誤消息msg –
'Not Found 請求的URL /test/test/redirect:/test/test/test.html/redirect: /test/test/test.html/redirect:/test/test/test.html/redirect:/test/test/test.html/test.html/test.html/redirect:/test/test/test.html/在此服務器上找不到test.html/test.html/redirect:/test/test/test.html/。 –
您只使用第二部分? (並刪除測試部分) – Croises