我希望能夠給所有子域名重定向到一個文件夾:htaccess的重定向所有子域到同一個目錄
RewriteCond %{HTTP_HOST} ^([^/.]+)\.example\.com$
RewriteRule (.+)$ "http://example.com/subdomains/%1" [L,P]
例如,如果一些訪問sub1.example.com
它將保持URL,但顯示example.com/subdomains/sub1
如果SUB1目錄不存在,它會顯示example.com/404
這可能嗎?
我試過上面的代碼,但它給我看:
Forbidden
You don't have permission to access /index.php on this server.
的WordPress說:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
,並在我的htaccess文件的頂部,是:
RewriteEngine On
DirectoryIndex index.php
RewriteCond %{HTTP_HOST} admin.domain.com$
RewriteRule ^(.*)$ /admin/system/$1 [L]
如果你直接去'http:// example.com/subdomains/sub1 /'怎麼辦?你是否也有'Forbidden'錯誤或者你有權訪問它?無論如何,儘管事實並非如此,你的代碼仍然可以工作。而且我認爲它實際上工作。當你有這個'禁止',你看到'sub1.example.com'爲url? –
沒有錯,沒有錯誤 – charlie
代碼對我來說也很好。禁止的問題可能由其他.htaccess設置引起,例如在IndexIgnore上。檢查你的位置。 –