Not logged in. · Lost password · Register
Forum: Non-English Discussion Japanese discussion RSS
URL末尾を .htmlにする方法
Avatar
gracia #1
Member for 2 months · 7 posts
Group memberships: Members
Show profile · Link to this post
Subject: URL末尾を .htmlにする方法
.htaccessを使って、URL書き換えを行っていますが
末尾に.htmlを付加する方法が分かりません。

以下現在の.htaccessです。

RewriteCond %{HTTPS} !=on
RewriteRule ^lib/exe/xmlrpc.php$      https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301]
#
RewriteRule ^_media/(.*)              lib/exe/fetch.php?media=$1  [QSA,L]
RewriteRule ^_detail/(.*)             lib/exe/detail.php?media=$1  [QSA,L]
RewriteRule ^_export/([^/]+)/(.*)     doku.php?do=export_$1&id=$2  [QSA,L]
RewriteRule ^$                        doku.php  [L]
RewriteCond %{REQUEST_FILENAME}       !-f
RewriteCond %{REQUEST_FILENAME}       !-d
RewriteRule (.*)                      doku.php?id=$1  [QSA,L]
RewriteRule ^index.php$               doku.php
Avatar
arz #2
Member for 2 months · 3 posts
Group memberships: Members
Show profile · Link to this post
graciaさん、こんばんは


下から2行目を...

RewriteRule (.*)                      doku.php?id=$1  [QSA,L]
 ↓
RewriteRule ^(.*)\.html$          doku.php?id=$1  [QSA,L]

でいきませんかね?
Avatar
gracia #3
Member for 2 months · 7 posts
Group memberships: Members
Show profile · Link to this post
ありがとうございます!

URL末尾に.htmlを付加すると表示されますが、
メニューからのURLに.htmlがついていないため、遷移する際にNotFoundになってしましました…
Avatar
gracia #4
Member for 2 months · 7 posts
Group memberships: Members
Show profile · Link to this post
RewriteCond %{REQUEST_FILENAME}       !-f
RewriteCond %{REQUEST_FILENAME}       !-d
RewriteRule ^(.*).html$               doku.php?id=$1  [QSA]
RewriteCond %{REQUEST_FILENAME}       !-f
RewriteCond %{REQUEST_FILENAME}       !-d
RewriteRule (.*)                      $1.html [R=301,L]
RewriteRule ^index.php$               doku.php

上記の様に変更したらうまくいきました。
何か不具合があるかもしれませんが。
Avatar
gracia #5
Member for 2 months · 7 posts
Group memberships: Members
Show profile · Link to this post
RewriteCond %{REQUEST_FILENAME}       !-f
RewriteCond %{REQUEST_FILENAME}       !-d
RewriteRule ^(.*)/index.html$         doku.php?id=$1  [QSA]
RewriteCond %{REQUEST_FILENAME}       !-f
RewriteCond %{REQUEST_FILENAME}       !-d
RewriteRule (.*)                      $1/index.html [R=301,L]

こっちのほうがいいかもしんないですね。
Avatar
gracia #6
Member for 2 months · 7 posts
Group memberships: Members
Show profile · Link to this post
上の方法だと編集ボタンをおしたときに現在表示しているページを再表示しちゃうんでダメですね。
Avatar
arz #7
Member for 2 months · 3 posts
Group memberships: Members
Show profile · Link to this post
おっと...

やっぱり実際にやってみないとダメですね^^;
誤情報ですみません...

えーと、名前空間にドットを全く使っていないという前提で...


1. 「.」がない場合は「.html」を加えて強制転送
RewriteRule ^([^\.]*)$      $1.html            [R]

2. 「.html」を無視してDokuWikiにQSAを渡す
RewriteRule ^(.*)\.html$   doku.php?id=$1 [QSA,L]


とかいう2段の書き換えでどうでしょう?
(また間違っているかもしれません...)


RewriteCond %{HTTPS} !=on
RewriteRule ^lib/exe/xmlrpc.php$      https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301]
#
RewriteRule ^_media/(.*)                 lib/exe/fetch.php?media=$1  [QSA,L]
RewriteRule ^_detail/(.*)                  lib/exe/detail.php?media=$1  [QSA,L]
RewriteRule ^_export/([^/]+)/(.*)     doku.php?do=export_$1&id=$2  [QSA,L]
RewriteRule ^$                               doku.php  [L]
RewriteCond %{REQUEST_FILENAME}       !-f
RewriteCond %{REQUEST_FILENAME}       !-d
RewriteRule ^([^\.]*)$                     $1.html [R]
RewriteRule ^(.*)\.html$                  doku.php?id=$1 [QSA,L]

RewriteRule ^index.php$                  doku.php [L]
Avatar
arz #8
Member for 2 months · 3 posts
Group memberships: Members
Show profile · Link to this post
あ〜違うかもw

末尾が「/」でも困るので

# 末尾が「/」でないときの処理
RewriteCond %{REQUEST_FILENAME}       !-f
RewriteCond %{REQUEST_FILENAME}       !-d
RewriteRule ^([^\.]*[^/])$               $1.html [R]
RewriteRule ^(.*)\.html$                  doku.php?id=$1 [QSA,L]
# 末尾が「/」だったときの処理
RewriteCond %{REQUEST_FILENAME}       !-f
RewriteCond %{REQUEST_FILENAME}       !-d
RewriteRule ^(.*)/$                        $1/<スタートページ名>.html [R,L]
#
RewriteRule ^index.php$                  doku.php [L]
This post was edited on 2010-01-28, 06:41 by arz.
Avatar
gracia #9
Member for 2 months · 7 posts
Group memberships: Members
Show profile · Link to this post
RewriteRule ^$                        doku.php  [L]

RewriteCond %{REQUEST_FILENAME}       !-f
RewriteCond %{REQUEST_FILENAME}       !-d
RewriteCond %{REQUEST_METHOD} =POST
RewriteRule (.*)                      doku.php?id=$1  [QSA,L]

RewriteCond %{REQUEST_FILENAME}       !-f
RewriteCond %{REQUEST_FILENAME}       !-d
RewriteRule ^(.*)\.html$              doku.php?id=$1  [QSA]

RewriteCond %{REQUEST_FILENAME}       !-f
RewriteCond %{REQUEST_FILENAME}       !-d
RewriteRule (.*)                      $1.html  [L,R=301]

RewriteRule ^index.php$               doku.php

これで今のところは動いています。
POST時は.htmlつかないようにすれば、編集ボタン押しても大丈夫でした。
Avatar
kazmiya #10
Member since Oct 2009 · 10 posts · Location: Tsukuba, Japan
Group memberships: Members
Show profile · Link to this post
gracia さま

もうほとんど解決されたようですが、一応。

リンク構文で生成される内部リンクのリンク先 URL に '.html' を追加
するには、ソースコードをいじる必要があります。以下の関数です。

  * inc/common.php の wl()
  * inc/html.php の html_btn()

gracia さんの場合は .htaccess による URL の書き換えを行っている
ようですので、$conf['userewrite'] が 1 である場合の処理を行って
いる箇所に変更を加えると、メニューなどのリンク URL にも '.html'
が付加されるようになります。変更点は mod_rewrite のルールととも
に以下の URL にまとめておきました。

  http://cloud.github.com/downloads/kazmiya/files/20100128_d…

# 行儀の悪いプラグインなどでは独自にリンクを作成している場合があ
# りますので、その場合は別途対応しなければなりません。

---

ただし、現在の gracia さんの方法や上記の方法では、ページ ID と
URL が一致しないため、ユーザの混乱を招く可能性があります。例えば、
hoge.html にリンクしたい場合に [[hoge.html|ほげ]] としても正しく
リンクされないという問題が発生します。この場合のページ ID は
'hoge' ですので、[[hoge|ほげ]] としなければなりません。結構紛ら
わしいです。

一番混乱の少ない解決策は、以下の方法だと思います。

  1. DokuWiki 標準添付の .htaccess による URL 書き換えを使用する。
  2. スタートページ名を 'start' から 'start.html' などに変更する。
     (conf/local.php で $conf['start'] = 'start.html'; など)
  3. 今後作成するページの名前を ***.html とする (緩いルール決め)。

もちろんこの方法は既存のページが多い場合や不特定多数が編集する
Wiki では使えないかもしれませんが、長い目で見ると一番影響が少な
いのではないかと思います (DokuWiki のバージョンアップも問題無く
行えます)。

こんな方法もありますよ、ということで。
Avatar
gracia #11
Member for 2 months · 7 posts
Group memberships: Members
Show profile · Link to this post
大変ご丁寧な回答ありがとうございます!

URL先の方法を試したところ、indexmenuプラグインから遷移するときに

ベースURL/./htmページ名

となってしまいました。
現在位置からの遷移だとうまくいくのですが。
arcticテンプレートのサイドバーはうまく.htmlが付加されませんでした。

kazmiya様の.htmlを名前につける方法のほうが良いのかなと思います。
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please note the verification code from the picture into the text field next to it.
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Go to forum
Imprint
This board is powered by the Unclassified NewsBoard software, 20090606-dev, © 2003-8 by Yves Goergen
Current time: 2010-03-19, 20:45:13 (UTC +01:00)
WikiForumIRCBugsGitXRefTranslate