[英]Rewrite subdomain to a folder and redirect that folder to a subdomain
我有一個重寫規則,將所有用戶從random.example.com
發送到/random/
但是我想這樣做,以便如果用戶要直接訪問/random/
,它將把他們重定向(重定向到非重寫)到子域。
這就是我所擁有的:
RewriteEngine on
# NO WWW
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
# USE RANDOM SUB DOMAIN WITH CONTENT IN SUB FOLDER
RewriteCond %{HTTP_HOST} random.example.com$
RewriteCond %{REQUEST_URI} !^/random
RewriteRule ^(.*)$ /random/$1 [L]
# SEND SNOOPERS AT SUB FOLDER TO SUB
Redirect ^(.*)$/random/$1 %{HTTP_HOST}random.example.com$
但是,對於最后一行,我收到服務器500錯誤。 基本上,它需要處理隨機目錄中出現的所有網址,例如:
http://example.com/random -> http://random.example.com/
http://example.com/random/fakeplace/ -> http://random.example.com/fakeplace/
http://example.com/random?id=4 -> http://random.example.com/?id=4
您的語法在最后一行是錯誤的。 您甚至在混合RewriteRule和Redirect。 嘗試這些規則。 我改變了幾件事。
RewriteEngine on
# NO WWW
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
# USE RANDOM SUB DOMAIN WITH CONTENT IN SUB FOLDER
RewriteCond %{HTTP_HOST} ^random\.example\.com$
RewriteRule !^random/? random%{REQUEST_URI} [NC,L]
RewriteCond %{THE_REQUEST} \s/random/([^\s]*) [NC]
RewriteRule ^ http://random.example.com/%1 [R=301,L]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.