2016-08-19 18 views
0

這就是我目前將URL從PC重定向到手機的時刻。.htaccess手機和電腦無法正確重定向查詢字符串

RewriteRule^http://m.example.com%{REQUEST_URI}? [R=301,L] 

上述代碼的問題是它切割?所有查詢字符串進行重定向到移動網址

現在這個時候會不會有問題,從http://www.example.com/bangkok/(原http://www.example.com/jobs-list-province.php?p_name=bangkok)重寫URL時

http://m.example.com/bangkok/ 

但是,這將有URL的問題,需要發送過查詢字符串,例如: http://www.example.com/keyword-search.php?s_keyword=analyst被重定向到http://m.example.com/keyword-search.php代替ħttp://m.example.com/keyword-search.php?s_keyword=analyst

所以,我試圖通過使用此代碼

要解決的問題
RewriteRule^http://m.example.com%{REQUEST_URI}? [QSA,R=301,L] 

或本規範

RewriteRule^http://m.example.com%{REQUEST_URI} [R=301,L] 

當我使用上面的代碼,它與重定向在 http://www.example.com/bangkok/問題變爲:http://m.example.com/bangkok/?p_name=bangkok代替。

我如何重寫,這樣 http://www.example.com/bangkok/http://m.example.com/bangkok/http://www.example.com/keyword-search.php?s_keyword=analysthttp://m.example.com/keyword-search.php?s_keyword=analyst

請參閱更多信息附加htaccess文件。感謝您的幫助。

#Redirect to www location 
RewriteEngine on 
RewriteBase/
rewritecond %{http_host} ^example.com [nc] 
rewriterule ^(.*)$ http://www.example.com/$1 [r=301,nc] 

rewriterule ^(bangkok)$ /jobs-list-province.php?p_name=$1 

# Check if mobile=1 is set and set cookie 'mobile' equal to 1 
     RewriteCond %{QUERY_STRING} (^|&)mobile=1(&|$) 
    RewriteRule^- [CO=mobile:1:%{HTTP_HOST}] 

# Check if mobile=0 is set and set cookie 'mobile' equal to 0 
    RewriteCond %{QUERY_STRING} (^|&)mobile=0(&|$) 
RewriteRule^- [CO=mobile:0:%{HTTP_HOST}] 

# cookie can't be set and read in the same request so check 
RewriteCond %{QUERY_STRING} (^|&)mobile=0(&|$) 
    RewriteRule^- [S=1] 

    # Check if this looks like a mobile device 
    RewriteCond %{HTTP:x-wap-profile} !^$ [OR] 
    RewriteCond %{HTTP_USER_AGENT} "android|blackberry|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC,OR] 
    RewriteCond %{HTTP:Profile}  !^$ 

# Check if we're not already on the mobile site 
    RewriteCond %{HTTP_HOST}   !^m\. 
    # Check to make sure we haven't set the cookie before 
    RewriteCond %{HTTP_COOKIE} !mobile=0(;|$) [NC]   

    RewriteRule^http://m.example.com%{REQUEST_URI}? [R=301,L] 
+1

把曼谷統治放在.htaccess的底部? –

+0

我試過了。它給出了相同的結果 – Arvin

+0

好吧,讓我再讀一遍這個問題:),這次更加小心 –

回答

0

你需要做兩件事情:

  1. (你已經嘗試過),是從

    RewriteRule^http://m.example.com%{REQUEST_URI}? [QSA,R=301,L]

    刪除問號,因爲它會阻止查詢字符串通過不變。

  2. 移動這樣的規則:

    rewriterule ^(bangkok)$ /jobs-list-province.php?p_name=$1

    的底部,因爲你不希望你的規則混合。首先手柄重定向到手機網站,然後檢查/bangkok重寫

相關問題