htaccessでデバイス別に振り分ける
Xサーバーで確認。
https://ドメイン.com => spでアクセスしたら/sp/にリダイレクト
https://ドメイン.com/sp/ => pcでアクセスしたら/にリダイレクト
トップページ以外も対応してるので、
例えば https://ドメイン.com/about/ にspでアクセスしたら
https://ドメイン.com/sp/about/ にリダイレクトされる。
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !/sp/
RewriteCond %{HTTP_USER_AGENT} (iPod|iPhone|Android.*Mobile|Windows.\ Phone)
RewriteRule ^(.*)$ sp/$1 [R]
RewriteCond %{REQUEST_URI} /sp/
RewriteCond %{HTTP_USER_AGENT} !(iPod|iPhone|Android.*Mobile|Windows.\ Phone)
RewriteRule ^sp/(.*)$ $1 [R]参考 https://www.itti.jp/web-design/htaccess-redirect/
htaccessでパラメーター付きURLをリダイレクト
# https://hoge.com/?ParameterName
# 上記パラメーター付きURLを以下にリダイレクト
# https://hoge.com/new.html
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{QUERY_STRING} ^ParameterName$
RewriteRule ^ /new.html? [R=301,L]
</IfModule>htaccessをルートディレクトリ以外に置く
# https://hoge.com/test/
# /test/に.htaccessファイルを作成した場合の挙動
# https://hoge.com/test/
# /test/に置いた.htaccessファイルで、上記URLを以下にリダイレクトしたい場合
# https://hoge.com/test/01/
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^ /test/01/ [R=301,L]
</IfModule>htaccessでアンカーリンク制御。ディレクトリ => アンカーリンクへと飛ばしたい場合
# 例) https://hoge.com/test/ => https://hoge.com/test/#link
# 上記のようにディレクトリをアンカーに飛ばす場合
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
# ひとつめ
RewriteRule ^kinmemai/genryo/best/$ /product/best/#link [R=301,L,NE]
# ふたつめ
RewriteRule ^kinmemai/genryo/gold/$ /product/gold/#link [R=301,L,NE]
</IfModule>
コメントを残す