Skip to content

Instantly share code, notes, and snippets.

@nishinoshake
Last active May 29, 2016 04:32
Show Gist options
  • Save nishinoshake/a2f1c874c5a7adeb03ba to your computer and use it in GitHub Desktop.
Save nishinoshake/a2f1c874c5a7adeb03ba to your computer and use it in GitHub Desktop.
PC/SPの振り分け
RewriteEngine on
RewriteBase /sample/html/
RewriteCond %{REQUEST_URI} !/sp/
RewriteCond %{HTTP_USER_AGENT} (iPod|iPhone|iPad|Android|Windows\ Phone)
RewriteRule ^(.*)$ sp/$1 [R]
RewriteBase /sample/html/
RewriteCond %{REQUEST_URI} /sp/
RewriteCond %{HTTP_USER_AGENT} !(iPod|iPhone|iPad|Android|Windows\ Phone)
RewriteRule ^sp/(.*)$ $1 [R]

###[R]とは Ridirectしますという宣言 R=301のようにするとパーマネントになる。 デフォルトはR=301のテンポラリが設定されている。

302 status code being used by default if none is specified http://httpd.apache.org/docs/current/rewrite/flags.html#flag_r

####[L]はラスト、ここでRewrite終わりという宣言 RewriteRule dir1/(.*) dir2/$1 [R,L] みたいに使うこともある。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment