動的URLより静的URLの方が検索エンジンにインデックスされやすいので
apacheのモジュール、mod_rewriteを利用して変換する方法。
.htaccessでの書式(例)
http://hoge.com/index.php?page=aaa&id=bbb
を
http://hoge.com/aaa/bbb.html
と表示させたい場合
動的URLの「index.php?page=aaa&id=bbb」の"aaa"の所が4行目の"$1"で、"bbb"の所が"$2"です。
4行目の「([0-9A-Za-z]+)/([0-9A-Za-z)]+).html$」の"([0-9A-Za-z)]+)"で数字を解釈(rewrite)し、aaa/bbb.htmlとして呼び出すことが出来るようになります。
apacheのモジュール、mod_rewriteを利用して変換する方法。
.htaccessでの書式(例)
http://hoge.com/index.php?page=aaa&id=bbb
を
http://hoge.com/aaa/bbb.html
と表示させたい場合
DirectoryIndex index.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9A-Za-z]+)/([0-9A-Za-z)]+)\.html$ index.php?page=$1&id=$2 [L]
http://hoge.com/aaa/bbb/ にする場合は最後の行を
RewriteRule ^([0-9A-Za-z]+)/([0-9A-Za-z)]+)/$ index.php?page=$1&id=$2 [L]
と記述。
動的URLの「index.php?page=aaa&id=bbb」の"aaa"の所が4行目の"$1"で、"bbb"の所が"$2"です。
4行目の「([0-9A-Za-z]+)/([0-9A-Za-z)]+).html$」の"([0-9A-Za-z)]+)"で数字を解釈(rewrite)し、aaa/bbb.htmlとして呼び出すことが出来るようになります。
