使用 .htaccess 檔案,我需要獲取任何 URL,只要它具有非 www 子域并將其重定向到不同的結構:
test.example.com -> example.com/r/test
another.example.com/foo/bar -> example.com/r/another
sub.example.com/q -> example.com/r/sub
www.example.com -> www.example.com
我已經接近了,但我似乎無法做到這一點。
uj5u.com熱心網友回復:
您可以在 htaccess 中使用以下規則:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^((?!www). )\.example\.com$ [NC]
RewriteRule ^ /r/%1 [L]
這應該重寫foobar.example.com為example.com/r/foobar. 重定向是內部意思,即您的瀏覽器 URL 不會改變。R=301如果您正在尋找 URL 的外部 301 重定向,則可以在您的規則中使用。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/433806.html
