.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
IfModule mod_rewrite.c
・もしURL書き換えモジュール、mod_rewriteが使えたら
RewriteEngine On
・書き換えを可能にする
RewriteBase /hogehoge/
・書き換えのルートは、Wordpressのディレクトリ”hogehoge”です
RewriteCond %{REQUEST_FILENAME} !-f
・リクエストされたURLが実在するファイル(!-f)ではなく
RewriteCond %{REQUEST_FILENAME} !-d
・リクエストされたディレクトリ(!-d)が実在しなかったら
RewriteRule . /hogehoge/index.php [L]
・どんなURI(.)にアクセスされても、/hogehoge/index.phpのページに飛ばしますという意味
・[L]は、定義の最終行(Last)を意味し、この行以降のRewriteRuleは無視という意味
WordPress › フォーラム » .htaccessの中身の意味がわかりません
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
というような記述をすると、www付きのアドレスにリダイレクトパラメータ付きでリダイレクトさせることが可能です。
また上記のサンプルコードのように[R=301,L]と,(カンマ)で区切ることにより複数のフラグを設定することも可能です。
今さら人に聞けない!WordPressで使われているmod_rewriteの説明書|クロノドライブ
2つの記載に分けて利用すれば問題無し。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
< IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.rdf$ /feed/rdf/ [L,R=301] </ IfModule > # BEGIN WordPress < IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </ IfModule > # END WordPress |
※[R]をつけるとブラウザのURLの表示も書きかわります。
-
(dash)A dash indicates that no substitution should be performed (the existing path is passed through untouched). This is used when a flag (see below) needs to be applied without changing the path.
※「"-"ハイフン」は何もしないの意。
http://httpd.apache.org/docs/current/ja/mod/mod_rewrite.html#rewriterule
RewriteRule ^(.*)\.html $1.php [R,L]
/(¥d+)(yen)/ =~ "price is 1980yen" $1 => "1980" $2 => "yen"