2012-03-16 65 views
1

,而不是假設我有我的網站上像這樣的文件:子域名重定向到一個特定的文件的文件夾

example.com/pages/live_report.php 

,現在我想,當用戶鍵入URL live.example.com,它指到上面的文件沒有我是強制重命名它。

我該怎麼做通過htaccess?

當然

我嘗試這個規則,建議上Redirect a subdomain to a directory using .htaccess

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^live\.example\.com 
RewriteRule ^(.*)$ /pages/live_report.php$1 [L] 

但這不工作

回答

2

如果不能在所有的工作,你很多沒有「設置AllowOverride全部」中虛擬主機文件。嘗試類似

deny from all 

,看的.htaccess正在處理

如果你要重定向到http://live.example.com/pages/live_report.php你需要使用一個完整的URI,如

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^live\.example\.com 
RewriteRule ^(.*)$ http://www.example.com/pages/live_report.php$1 [L] 
+0

我不想重定向live.example.com到該文件只是它是一個http://live.example.com/pages/live_report.php URL rewrited但是我測試你在Chrome中排除,但不顯示發現錯誤 – 2012-03-16 16:28:55

+0

你有'live_report.php'在正確的文件夾? – scibuff 2012-03-16 16:31:04

+0

是的,這是正確的。但注意:當我通過cPanel創建一個新的子域時,顯示此消息,並在幾個小時後顯示正確並正常工作。是否有可能導致這個問題 – 2012-03-16 16:37:28

0

也許這將幫助(未測試):

RedirectMatch 301 ^/folder http://www.mydomain.com/file.html 

or this:

RedirectMatch 301 ^/folder(.*) http://www.mydomain.com/file.html 
+0

我想使用子域 – 2012-03-16 16:27:06

+0

,但是當你有子域,它有一個登陸目錄?把.htaccess放在那裏 – Andrew 2012-03-16 16:58:58

相關問題