Mod Rewrite

mod rewrite

# Sample1
RewriteCond %{REQUEST_URI} ^/test/([0-9]+)$
RewriteRule ^/test/([0-9]+)$ /index.php?module=Test&action=Test1&id=$1 [L,QSA]

QSAをつけると、パラメータを自動的にくっつけてくれる
# Sample2
RewriteCond %{REQUEST_URI} ^/test1/test1/([0-9]+)$ [OR]
RewriteCond %{REQUEST_URI} ^/test1/test1/test1/([0-9]+)$ [OR]
RewriteCond %{REQUEST_URI} ^/test1/test1/test1/test1/([0-9]+)$ [OR]
RewriteRule ^/test/([0-9]+)$ /index.php?module=Test&action=Test2&id=$1 [L,QSA]

RewriteCondを複数指定することも可能
デフォルトでは、RewriteCond AND RewriteCond AND RewriteCondで検索されるが、
[OR]をつけることで、RewriteCond OR RewriteCond OR RewriteCondで検索される

Mojavi URL Sample1

http://localhost/admin/module/aa/bbb/ccc/ddd/

# mod rewrite
RewriteRule ^(.*)\.(js|ico|gif|jpg|png|css|html|txt|csv|asp)$ $1.$2 [L]

# mod rewrite admin
RewriteRule !^(/)?admin/indadmin/? - [C]
RewriteRule ^/admin/([^/]+)/([^/]+)/(.*) /admin/indadmin/$3?module=$1&action=$2

RewriteRule ^/admin/indadmin/([^/]+)/([^/]+)(.*)$ /admin/indadmin$3?$1=$2 [QSA,N]
RewriteRule ^/admin/indadmin/([^/]+)(/)?$ /admin/indadmin/?$1= [QSA]

RewriteRule ^/admin/indadmin/?$ /admin/index.php [QSA,L]

# mod rewrite user
RewriteRule !^(/)?ind/? - [C]
RewriteRule ^/([^/]+)/([^/]+)/(.*) /ind/$3?module=$1&action=$2

RewriteRule ^/ind/([^/]+)/([^/]+)(.*)$ /ind$3?$1=$2 [QSA,N]
RewriteRule ^/ind/([^/]+)(/)?$ /ind/?$1= [QSA]

RewriteRule ^/ind/?$ /index.php [QSA,L]

Mojavi URL Sample2

adminだけ以下のURLで運用 http://localhost/admin/index.php?module=Top&action=Index&aa=bbb&ccc=ddd

# mod rewrite
RewriteEngine on
RewriteLog /home/m-matsubara/logs/rewrite.log
RewriteLogLevel 2

# mod rewrite
RewriteRule ^(.*)\.(js|ico|gif|jpg|png|css|html|txt|csv|asp)$ $1.$2 [L]

# mod rewrite admin
RewriteRule ^/admin/(.*)$ /admin/$1 [QSA,L]

# mod rewrite user
RewriteRule !^(/)?ind/? - [C]
RewriteRule ^/([^/]+)/([^/]+)/(.*) /ind/$3?module=$1&action=$2
RewriteRule ^/ind/([^/]+)/([^/]+)(.*)$ /ind$3?$1=$2 [QSA,N]
RewriteRule ^/ind/([^/]+)(/)?$ /ind/?$1= [QSA]
RewriteRule ^/ind/?$ /index.php [QSA,L]

Mojavi URL Sample3

adminだけ以下のURLで運用 http://localhost/admin/module/action/index.php?aaa=bbb&ccc=ddd

# mod rewrite
RewriteEngine on
RewriteLog /home/m-matsubara/logs/rewrite.log
RewriteLogLevel 2

# mod rewrite
RewriteRule ^(.*)\.(js|ico|gif|jpg|png|css|html|txt|csv|asp)$ $1.$2 [L]

# mod rewrite admin
RewriteRule ^/admin/([^/]+)/([^/]+)/(index.php)?$ /admin/index.php?module=$1&action=$2 [QSA,L]

# mod rewrite user
RewriteRule !^(/)?ind/? - [C]
RewriteRule ^/([^/]+)/([^/]+)/(.*) /ind/$3?module=$1&action=$2
RewriteRule ^/ind/([^/]+)/([^/]+)(.*)$ /ind$3?$1=$2 [QSA,N]
RewriteRule ^/ind/([^/]+)(/)?$ /ind/?$1= [QSA]
RewriteRule ^/ind/?$ /index.php [QSA,L]


Comment



Counter: 7506, today: 1, yesterday: 1

トップ   編集 凍結解除 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2013-09-24 (火) 14:55:51 (1881d)