2017-01-26 9 views
1

私のサイトの.htaccessファイルに問題があります。htaccess - モバイルウェブサイト(サブドメイン上)にリダイレクトしようとするときの問題

私が得るエラーは、何度もリダイレクトしようとしていることです。

現時点では、デスクトップ上にあるときはいつでも、URLをサブフォルダ/distにリダイレクトする必要があります。モバイルの場合は、代わりにモバイル版のモバイルサイトにアクセスする必要がありますmobile.

私のhtaccessファイルで始まるサブドメインは、次のようになります。

RewriteEngine on 
RewriteBase/

# Check if this is the noredirect query string 
RewriteCond %{QUERY_STRING} (^|&)m=0(&|$) 

# Set a cookie, and skip the next rule 
RewriteRule^- [CO=mredir:0:www.mywebsite.com/dist] 

RewriteCond %{HTTP_HOST} ^mywebsite\.com$ [OR] 
RewriteCond %{HTTP_HOST} ^www\.mywebsite\.com$ 
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$ 
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$ 
RewriteRule ^/?$ "http\:\/\/www\.mywebsite\.com\/dist" [R=301,L] 

# Check if we're not already on the mobile site 
RewriteCond %{HTTP_HOST}   !^m\. 

# Can not read and write cookie in the same request, must duplicate condition 
RewriteCond %{QUERY_STRING} !(^|&)m=0(&|$) 

# Check to make sure we haven't set the cookie before 
RewriteCond %{HTTP_COOKIE}  !^.*mredir=0.*$ [NC] 

# Now redirect to the mobile site 
RewriteRule^http://mobile.mywebsite.com [R,L] 

は誰が助けることができますか?

がこの

おかげ

+0

は役立つだろう。 – DmitriD

+0

リソースの読み込みに失敗しました:net :: ERR_TOO_MANY_REDIRECTS – Nick

+0

あなたのモバイルサイトは 'm.'または' mobile.'で始まりますか? – anubhava

答えて

1

のようなもので、私の最初の試みであるあなたは、このようにそれを持つことができます。あなたにも、エラーメッセージを投稿した場合

RewriteEngine on 
RewriteBase/

# Check if this is the noredirect query string 
RewriteCond %{QUERY_STRING} (^|&)m=0(&|$)  
# Set a cookie, and skip the next rule 
RewriteRule^- [CO=mredir:0:www.mywebsite.com/dist] 

RewriteCond %{HTTP_HOST} ^(?:www\.)?mywebsite\.com$ [NC] 
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$ 
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$ 
RewriteRule ^/?$ http://www.mywebsite.com/dist [R=301,L] 

# Check if we're not already on the mobile site 
RewriteCond %{HTTP_HOST} !^(m|mobile)\. [NC]  
# Can not read and write cookie in the same request, must duplicate condition 
RewriteCond %{QUERY_STRING} !(^|&)m=0(&|$) [NC]  
# Check to make sure we haven't set the cookie before 
RewriteCond %{HTTP_COOKIE} !^.*mredir=0 [NC] 
# check mobile agents 
RewriteCond %{HTTP_ACCEPT} "text\/vnd\.wap\.wml|application\/vnd\.wap\.xhtml\+xml" [NC,OR] 
RewriteCond %{HTTP_USER_AGENT} "sony|symbian|nokia|samsung|mobile|windows ce|epoc|opera" [NC,OR] 
RewriteCond %{HTTP_USER_AGENT} "mini|nitro|j2me|midp-|cldc-|netfront|mot|up\.browser|up\.link|audiovox" [NC,OR] 
RewriteCond %{HTTP_USER_AGENT} "blackberry|ericsson,|panasonic|philips|sanyo|sharp|sie-" [NC,OR] 
RewriteCond %{HTTP_USER_AGENT} "portalmmm|blazer|avantgo|danger|palm|series60|palmsource|pocketpc" [NC,OR] 
RewriteCond %{HTTP_USER_AGENT} "smartphone|rover|ipaq|au-mic,|alcatel|ericy|vodafone\/|wap1\.|wap2\.|iPhone|android" [NC] 
# Now redirect to the mobile site 
RewriteRule^http://mobile.mywebsite.com [R=302,NE,L] 
+0

いいえ、私はデスクトップ上にあっても毎回モバイルバージョンにリダイレクトします。 – Nick

+0

そのためには、ユーザエージェントをチェックする必要があり、そのチェックはあなたの質問にはありませんでした。 – anubhava

+0

この回答によれば、モバイルデバイスではチェックが機能します: http://stackoverflow.com/questions/3680463/mobile-redirect-using-htaccessなぜ私の場合ではないのですか? これまでのおかげで、 – Nick

関連する問題