1

我有一個.ne.ro域(在羅馬尼亞註冊的),遊客可以帶或不帶「WWW」請輸入:htaccess的,重定向虛擬子域網址參數

http://mydomain.ne.ro
http://www.mydomain.ne.ro

我想將http://123.mydomain.ne.ro重定向到http://mydomain.ne.ro?id=123。如果用'www | mail | ftp'​​輸入的訪問者必須被視爲非參數(顯然)。我試過htaccess subdomain redirct with last url parameter,但沒有奏效。

當前代碼:

# edited on 05/April/2011 as suggested: 
RewriteEngine on 
RewriteCond %{HTTP_HOST} !^www\.mydomain\.ne\.ro$ 
RewriteCond %{HTTP_HOST} ^(.*)\.mydomain\.ne\.ro$ 
RewriteRule ^$ /index.php?id=%1 [R,L] 


託管在hostgator's business plan(Linux)的,註冊在nic.ro,只是如果問。

+0

什麼是當前的重定向規則? – 2010-11-03 17:25:55

+0

有人嗎?我是新手,並陷入這個問題。 – quantme 2010-11-04 02:10:53

+0

你不需要任何重定向。所有請求**已經**登陸您的索引。 – 2010-12-09 06:20:10

回答

4

許多建議代碼(感謝supersuphot)和大量的調查研究後,終於我找到了答案。

首先,我添加子域名*mydomain.ne.ro,指出域文件夾/路徑:

Create subdomain *, hostgator shared account

然後我上傳與下一個代碼.htaccess文件:

RewriteEngine on 
RewriteCond %{HTTP_HOST} !^www\.mydomain.ne.ro 
RewriteCond %{HTTP_HOST} ^(.+).mydomain.ne.ro 
RewriteRule ^([^/]*)$ http://mydomain.ne.ro/?id=%1 [P,L] 

這個工程太:

RewriteEngine on 
RewriteCond %{HTTP_HOST} !^www\.mydomain\.ne\.ro$ 
RewriteCond %{HTTP_HOST} ^(.*)\.mydomain\.ne\.ro$ 
RewriteRule ^$ /index.php?id=%1 [P,L] 

最重要的事情是P代替[R在最後一行,以保持原來的子域。檢查this answerrelated question

1
RewriteEngine on 
RewriteCond %{HTTP_HOST} !^www\.mydomain\.ne\.ro$ 
RewriteCond %{HTTP_HOST} ^(.*)\.mydomain\.ne\.ro$ 
RewriteRule ^$ http://mydomain.ne.ro?id=%1 [R,L] 
+0

沒有工作): – quantme 2011-04-06 01:38:40

+0

嘗試再次編輯。 – supersuphot 2011-04-12 10:01:40

+0

我嘗試過,沒有積極的結果。你的規則讓我研究並最終得到了它。 – quantme 2011-04-12 19:10:43

1

哇量子!

我在尋找的代碼,因爲這兩天,終於誒...

你的第一個代碼是非常適合我

RewriteRule ^([^/]*)$ http://mydomain.ne.ro/?id=%1 [P,L] 

你也可以用這個變化(大寫或小寫字母)

RewriteRule ^(.*)$ http://mydomain.ne.ro/?id=%1 [P,L] 

非常感謝quantme