2011-09-21 96 views
6

我寫了下面的規則在.htaccess的.htaccess子域參數在查詢字符串無法訪問

RewriteCond %{HTTP_HOST} ^([^\.]+)\.domain\.com 
RewriteCond %1 !^www$ [NC] 
RewriteCond %{REQUEST_URI} ^/news/news-details\.php$ 
RewriteRule (.*) news.php?div=%1 

它的作用是傳輸請求的news.php文件與DIV變量爲news/news-details.php。我不需要div這樣。我需要使用域名寫入的子域名的值,例如用戶來自user.domain.com/news/news-details.php。我需要news.php文件中的div變量爲用戶,即news.php?div=user

編輯: 這裏現在是.htaccess的代碼,它是根新聞詳情頁選項

+FollowSymLinks 
RewriteEngine on 

# For Accessing News Details Page for root http://www.domain.com/news/news-details.php 
RewriteCond %{HTTP_HOST} ^www.domain\.com [NC] 
RewriteRule ^news/news-details.php$ news.php [QSA,NC,L] 


# For Accessing News Details Page http://user.domain.com/news/news-details.php 
RewriteCond %{HTTP_HOST} ^(.+)\.domain\.com [NC] 
RewriteCond %{HTTP_HOST) !^www\. 
RewriteRule ^news/news-details.php$ news.php?div=%1 [QSA,NC,L 


# For www.domain.com it should go to the index page 
RewriteCond %{HTTP_HOST} ^(www\.)?domain.com$ [NC] 
RewriteRule ^(.*)$ index.php [NC,L] 


# For Accessing Divisions Page user.domain.com should go to domain.com/divisions.php?division=user 
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ 
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com$ 
RewriteRule ^$ /divisions.php?division=%1 [L] 

再次編輯導致問題:

下面這兩個規則是衝突的

# For www.domain.com it should go to my-index.php page 
# 
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC] 
RewriteRule ^(.*)$ my-index.php [NC,L] 


# For Page URL http://www.domain.com/news/news-details.php 
# 
RewriteCond %{REQUEST_URI} ^/news/news\-details\.php [NC] 
RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC] 
RewriteRule ^(.*)$ my-news.php [NC,QSA,L] 

回答

11

試試這個:

RewriteCond %{REQUEST_URI} ^/news/news\-details.php$ 
RewriteCond %{HTTP_HOST} ^([a-z0-9]+)\.domain\.com$ [NC] 
RewriteCond %1 !^www$ [NC] 
RewriteRule ^(.*)$ news.php?div=%1 [NC,QSA,L] 

RewriteCond %{REQUEST_URI} ^/news/news\-details\.php [NC] 
RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC] 
RewriteRule ^(.*)$ news.php [NC,QSA,L] 

RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php [NC,QSA,L] 

RewriteCond %{HTTP_HOST} ^([a-z0-9]+)\.domain\.com$ [NC] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ divisions.php?division=%1 [NC,QSA,L] 
+0

是的,這是工作的動態域名,但是當我輸入www.domain.com/news/news-details.php它帶我到索引文件。我希望這個指向沒有用戶參數的同一個新聞文件?你怎麼做 – HardCode

+0

你的意思是當我輸入:www.domain.com我看到news.php(沒有參數),當我使用:user.domain.com我使用:php?user = user? –

+0

不,當我輸入www.domain.com/news/news-details.php它應該去news.php,但沒有參數和子域你寫的代碼工作正常。但是現在當我輸入www.domain.com/news/news-details.php時,它會帶我到index.php文件中。不是news.php? – HardCode

相關問題