Skip to content

Instantly share code, notes, and snippets.

@katsuobushiFPGA
Last active April 15, 2017 01:24
Show Gist options
  • Save katsuobushiFPGA/c4ab000c65b958db3740b0ad6d0c010c to your computer and use it in GitHub Desktop.
Save katsuobushiFPGA/c4ab000c65b958db3740b0ad6d0c010c to your computer and use it in GitHub Desktop.
.htaccessに関するメモ
###CakePHPで一部だけコントロール下にしたい
- httpdocs (ドキュメントルート)
- a
-index.html
- b
-index.html
- c
-index.html
- d
-index.html
この中の、cだけCakePHPで制御できるようにする。
そのためには、c直下に下記のような.htaccessを書く。
.htaccess
---
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} (^/c/)
RewriteCond %{REQUEST_URI} !(^/c/index.html)
RewriteRule ^ ../index.php [L]
</IfModule>
---
これにより、/c/でアクセスされたときは、cakephpで処理振り分けをするようにできる。
/c/index.htmlの場合は、index.htmlを表示させる。
###トレイリングスラッシュを付与
###末尾にスラッシュつけるやつ
# ファイルやディレクトリが存在すれば表示
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
# add Trailing Slash
RewriteRule ^(.+[^/])$ /$1/ [R=301,L]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment