1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

htaccess記述まとめ

Posted at

基本はレンタルサーバーでの記述

.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
# ここに記述をする
</IfModule>

リダイレクト

.htaccess
# 特定のディレクトリをリダイレクト
# AAA.com/news/ → AAA.com/product/news/
RewriteRule ^news/$ product/news/ [R=301,L]
.htaccess
# 特定のページをリダイレクト
# AAA.com/company/about.html → AAA.com/company/
RewriteRule ^company/about.html$ /company/ [R=301,L]
.htaccess
# パラメーター付きURLをリダイレクト
# AAA.com/news/?item=hoge → AAA.com/news/
RewriteCond %{QUERY_STRING} ^item=hoge$
RewriteRule ^news/$ /news/? [L,R=301]

# パラメーター付きURLをリダイレクト(複数つなげることも可)
# AAA.com/news/?item=hoge → AAA.com/news/
# AAA.com/news/?item=foo → AAA.com/news/
# 複数設定する場合は[OR]を指定
RewriteCond %{QUERY_STRING} ^item=hoge$ [OR]
RewriteCond %{QUERY_STRING} ^item=foo
RewriteRule ^news/$ /news/? [L,R=301]
.htaccess
# パラメーター付きURLをリダイレクト
# AAA.com/news/page/2/?item=hoge → AAA.com/news/
RewriteCond %{QUERY_STRING} ^item=hoge$
RewriteRule ^news/page/([0-9]+)/$ /news/? [L,R=301]

「QUERY_STRING」でクエリーを見にいく。
複数指定も可。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?