はまった、rewrite。
いろいろ調べてわかったことをメモしておく。
RewriteCondでマッチしたパラメータは%1で取れる
Rewrite後のURLで Urlencodeされたく無い場合は、NEをつける
クエリストリングを消したいときは、Ruleの最後に?をつける。
サンプル
/test/test.html?param1=1
を
/test/newtest.html#param1=1
にRewriteしたい場合
RewriteCond %{THE_REQUEST} ^GET\ /test/test.html\?(.*)\ HTTP(.*)$
RewriteRule ^.* http://(自分のドメインにして)/test/search-result.html#%1? [NE,L]
で、できると思います!
Rewriteで参考にさせていただいているサイトは、↓です。
http://blog.dawgsdk.org/weblog/archives/411011
2013年8月30日金曜日
2013年8月6日火曜日
[apache] リダイレクトの書き方
■/news/index.php?cat=1 を /news/cat1/index.html へリダイレクトする際の書き方
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} ^/news/index.php$ [NC]
RewriteCond %{QUERY_STRING} "cat=1"
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /news/cat1/index.html? [R=301,L]
※最後に?を付けないと、/news/cat1/index.html?cat=1 となってしまうから ? をつけましょう。
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} ^/news/index.php$ [NC]
RewriteCond %{QUERY_STRING} "cat=1"
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /news/cat1/index.html? [R=301,L]
※最後に?を付けないと、/news/cat1/index.html?cat=1 となってしまうから ? をつけましょう。
2013年8月2日金曜日
[PHP] ファイルを必ず読み込ませる
auto_prepend_file
が便利。
必ず読み込むので、定数定義などはこのファイルにしておけば簡単です。
.htaccess には ↓のように書いておきます。
php_value auto_prepend_file /var/www/html/_php/auto_inc.php
php_value display_errors stdout
が便利。
必ず読み込むので、定数定義などはこのファイルにしておけば簡単です。
.htaccess には ↓のように書いておきます。
php_value auto_prepend_file /var/www/html/_php/auto_inc.php
php_value display_errors stdout
登録:
投稿 (Atom)