.htaccessとJavascriptについて

当サイトでは、各テンプレートのソースとともに「.htaccess」と「text-clear」というファイルを同梱して配布していますが、今般、「これがないとどうなるの?」というご質問をいただきましたので、ここでご説明させていただきます。

.htaccessファイルについて

当サイトのテンプレートは、W3Cの勧告に準拠したXHTMLコードで記載しています。このW3Cの勧告の中に「XHTMLでコーディングする場合は、1行目にXHTML宣言を記述しなさい」というものがあります。

<?xml version="1.0" encoding="UTF-8"?>

これがXHTMLの宣言文なのですが、この記述があると、拡張子を「php」にしてもphpが作動しないという不具合があります。

「XHTML宣言文があってもphpを動かしてくださいよ」という命令を出してあげれば回避できるわけですが、この命令を.htaccessファイルで行っています。

つまり、「MTでphpは使わないよ~」という場合は.htaccessは必要ないわけです。しかし、phpを利用する方も当然いらっしゃる(私自身利用してますし)と思い、テンプレートと一緒に配布させていただきました。

text-clear.jsについて

.htaccessと一緒に配布されている「text-clear.js」というファイルもW3Cの勧告に準拠する対策のひとつです。

個別ページにコメント入力フォームがありますが、ここで使うtextarea(コメント本文を記述する部分)には、W3Cから「必ずコメントを入れておきなさい」という勧告が出されています。しかし、勧告通りテキストを入れておくと、コメント入力の際、既に入力されているテキストを一旦消すという無駄な作業が発生します。

これを回避するために、textareaがアクティブになったときに既に入力されているテキストを消してあげているのが前述の「text-clear.js」なんです。

「無駄にJavascriptは使いたくない」「多少勧告に準拠してなくても問題ない」という方は、エントリー・アーカイブ(ソース)のtextarea内に記述されている「ここにコメントを入力」というテキストを削除していただければ、text-clear.jsは必要なくなります。

なくても支障はありませんが.....

ということで、.htaccessとtext-clear.jsの2ファイルは、なくても問題はありません。ただ、より正確なHTMLコーディング、より快適なサイトにするためにはあった方が良いと思いますので、できれば解説にある通りにアップしていただければと思います。

UpDate » 06/08/29

MTテンプレートDB内検索


Warning: include() [function.include]: URL file-access is disabled in the server configuration in /virtual/wdstyle/public_html/mt-template.wdstyle.net/tpl_info/about_htaccess_javascript.html on line 108

Warning: include(http://mt-template.wdstyle.net/module/side_tpl_category.html) [function.include]: failed to open stream: no suitable wrapper could be found in /virtual/wdstyle/public_html/mt-template.wdstyle.net/tpl_info/about_htaccess_javascript.html on line 108

Warning: include() [function.include]: Failed opening 'http://mt-template.wdstyle.net/module/side_tpl_category.html' for inclusion (include_path='.:/usr/local/lib/php') in /virtual/wdstyle/public_html/mt-template.wdstyle.net/tpl_info/about_htaccess_javascript.html on line 108

Warning: include() [function.include]: URL file-access is disabled in the server configuration in /virtual/wdstyle/public_html/mt-template.wdstyle.net/tpl_info/about_htaccess_javascript.html on line 111

Warning: include(http://mt-template.wdstyle.net/module/amazon.html) [function.include]: failed to open stream: no suitable wrapper could be found in /virtual/wdstyle/public_html/mt-template.wdstyle.net/tpl_info/about_htaccess_javascript.html on line 111

Warning: include() [function.include]: Failed opening 'http://mt-template.wdstyle.net/module/amazon.html' for inclusion (include_path='.:/usr/local/lib/php') in /virtual/wdstyle/public_html/mt-template.wdstyle.net/tpl_info/about_htaccess_javascript.html on line 111

Warning: include() [function.include]: URL file-access is disabled in the server configuration in /virtual/wdstyle/public_html/mt-template.wdstyle.net/tpl_info/about_htaccess_javascript.html on line 114

Warning: include(http://mt-template.wdstyle.net/module/feed.html) [function.include]: failed to open stream: no suitable wrapper could be found in /virtual/wdstyle/public_html/mt-template.wdstyle.net/tpl_info/about_htaccess_javascript.html on line 114

Warning: include() [function.include]: Failed opening 'http://mt-template.wdstyle.net/module/feed.html' for inclusion (include_path='.:/usr/local/lib/php') in /virtual/wdstyle/public_html/mt-template.wdstyle.net/tpl_info/about_htaccess_javascript.html on line 114