
我下面有這段程式碼,應該會將子網域重定向到 .htaccess 中的目錄。我想做的是讓我網站上的每個使用者的個人資料都位於 username.mysite.com。我已經更改了通配符的 DNS 記錄和我之前使用過的程式碼,但由於某種原因它不再是了。有人可以幫忙嗎,謝謝。
RewriteBase /
RewriteCond s%{HTTPS} ^((s)on|s.*)$ [NC]
RewriteRule ^/*(.+/)?([^.]*[^/])$ http%2://%{HTTP_HOST}/$1$2/ [L,R=301]
RewriteCond %{HTTP_HOST} ^website\.?com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.website\.?com [NC]
RewriteCond %{REQUEST_URI} !/
RewriteRule ^(.*)$ $1 [L]
RewriteBase /
RewriteCond s%{HTTPS} ^((s)on|s.*)$ [NC]
RewriteRule ^/*(.+/)?([^.]*[^/])$ http%2://%{HTTP_HOST}/$1$2/ [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.website\.com
RewriteCond %{HTTP_HOST} ([^.]+)\.website\.com$ [NC]
RewriteCond %{REQUEST_URI} !userdir/
RewriteRule ^(.*)$ userdir/$1 [L]
答案1
你看過嗎mod_vhost_alias?它開箱即用地處理這個用例。
答案2
首先新增到您的 Apache 配置:
RewriteLog /tmp/rwlog.txt
RewriteLogLevel 9
運行 user.website.com 的測試,然後停用它(這對效能來說很困難),讓我們看看日誌檔案說了什麼。在日誌中的某個時刻,您會發現哪裡出了問題...