.htaccessでwww無しとindex.html無しのURLに統一する記述は?
Posted: 2012年11月03日(土) 17:04
-----
ご利用のサーバ:
MODXのバージョン:1.0.6J-r8
PHPのバージョン:5.33
MySQLのバージョン:5.0.95
ブラウザ:FF16.02
-----
いつもお世話になっています。
最近多くて申し訳ございません。
新しいバージョンをアップデートする時は、以前から使っている.htaccessをそのまま使用できるので問題ないのですが、新規でインストールするにはhtaccess.tplを土台にして作成しなくていけませんが、以前から比べるとあまりにも中味が少なくて、どのように編集すれば良いのか戸惑っています。
www無しとindex.html無しのURLに統一したいのですが、ググっても記述の違いが結構あって正解が分からないのですがご教授頂けませんでしょうか?
www無しのURLに統一する記述では、
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.example\.com
RewriteRule (.*) http://example.com/$1 [R=301,L]
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(http://www.example.com)(:80)? [NC]
RewriteRule ^(.*) http://example.com/$1 [R=301,L]
((:80)?が付く)
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.example\.com
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
(Options FollowSymLinksが付く)
の違いがあり、あるサイトのMODxでは
# Rewrite domain.com -> http://www.domain.com -- used with SEO Strict URLs plugin
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^example\.com [NC]
RewriteRule (.*) http://example.com/$1 [R=301,L]
となっていましたが、RewriteCond %{HTTP_HOST} !^example\.com [NC]の部分は、!^www.example\.com [NC]とwwwは入れなくて良いのでしょうか?ずっとwwwを入れたまま使っていましたけど・・・・・
次にindex.html無しのURLに統一する場合ですが、
Options FollowSymLinks
RewriteEngine on
RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ http://www.example.com/$1 [R=301,L]
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ http://www.example.com/$1 [R=301,L]
(+がついている)
RewriteEngine on
RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ http://www.example.com/$1 [R=301,L]
(Options FollowSymLinksがない)
の違いがあります。
それで以前の.htaccessは(いま使用中)
# For full documentation and other suggested options, please see
# http://svn.modxcms.com/docs/display/MODx096/Friendly+URL+Solutions
# including for unexpected logouts in multi-server/cloud environments
# and especially for the first three commented out rules
#php_flag register_globals Off
#AddDefaultCharset utf-8
#php_value date.timezone Asia/Tokyo
# Options +FollowSymlinks
RewriteEngine On
RewriteBase /
# Fix Apache internal dummy connections from breaking [(site_url)] cache
RewriteCond %{HTTP_USER_AGENT} ^.*internal\ dummy\ connection.*$ [NC]
RewriteRule .* - [F,L]
# Rewrite domain.com -> http://www.domain.com -- used with SEO Strict URLs plugin
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www.example\.com [NC]
RewriteRule (.*) http://example.com/$1 [R=301,L]
# Exclude /assets and /manager directories and images from rewrite rules
RewriteRule ^(manager|assets)/*$ - [L]
RewriteRule \.(jpg|jpeg|png|gif|ico)$ - [L]
# For Friendly URLs
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
# Reduce server overhead by enabling output compression if supported.
#php_flag zlib.output_compression On
#php_value zlib.output_compression_level 5
# For UTF-8
# php_flag output_buffering Off
# php_value output_handler none
# php_value default_charset UTF-8
# php_value mbstring.language japanese
# php_flag mbstring.encoding_translation On
# php_value mbstring.http_input auto
# php_value mbstring.http_output UTF-8
# php_value mbstring.internal_encoding UTF-8
# php_value mbstring.substitute_character none
# For EUC-JP
# php_flag output_buffering Off
# php_value output_handler none
# php_value default_charset EUC-JP
# php_value mbstring.language japanese
# php_flag mbstring.encoding_translation On
# php_value mbstring.http_input auto
# php_value mbstring.http_output EUC-JP
# php_value mbstring.internal_encoding EUC-JP
となっていましたが、# Reduce server overhead by enabling output compression if supported.以下の部分は恐らく不要だと思います。
それで最終的にwww無しとindex.html無しのURLに統一する場合はhtaccess.tplの編集は下記のようで良いのでしょうか
# http://modx.jp/docs/admin/htaccess.html
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
# MODXをサブディレクトリにインストールしている場合は「/modx」などに。
# Rewrite domain.com -> http://www.domain.com -- used with SEO Strict URLs plugin
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^example\.com [NC]
RewriteRule (.*) http://example.com/$1 [R=301,L]
RewriteEngine On
RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ http://example.com/$1 [R=301,L]
分かっている方から見れば適宜編集すればすぐできるのでしょうが、私なんかは数時間もこれに取り組んで難儀しています。出来れば、こうしたければ、ここだけ変更すれば良いですよ、みたいな長いテンプレートを添付して頂けると有難いのですが・・・・・
勝手な願望で申し訳ありません。
結論までが長いのですが、最後の.htaccessの記述が適性かどうか判断をお願い致します。
ご利用のサーバ:
MODXのバージョン:1.0.6J-r8
PHPのバージョン:5.33
MySQLのバージョン:5.0.95
ブラウザ:FF16.02
-----
いつもお世話になっています。
最近多くて申し訳ございません。
新しいバージョンをアップデートする時は、以前から使っている.htaccessをそのまま使用できるので問題ないのですが、新規でインストールするにはhtaccess.tplを土台にして作成しなくていけませんが、以前から比べるとあまりにも中味が少なくて、どのように編集すれば良いのか戸惑っています。
www無しとindex.html無しのURLに統一したいのですが、ググっても記述の違いが結構あって正解が分からないのですがご教授頂けませんでしょうか?
www無しのURLに統一する記述では、
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.example\.com
RewriteRule (.*) http://example.com/$1 [R=301,L]
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(http://www.example.com)(:80)? [NC]
RewriteRule ^(.*) http://example.com/$1 [R=301,L]
((:80)?が付く)
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.example\.com
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
(Options FollowSymLinksが付く)
の違いがあり、あるサイトのMODxでは
# Rewrite domain.com -> http://www.domain.com -- used with SEO Strict URLs plugin
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^example\.com [NC]
RewriteRule (.*) http://example.com/$1 [R=301,L]
となっていましたが、RewriteCond %{HTTP_HOST} !^example\.com [NC]の部分は、!^www.example\.com [NC]とwwwは入れなくて良いのでしょうか?ずっとwwwを入れたまま使っていましたけど・・・・・
次にindex.html無しのURLに統一する場合ですが、
Options FollowSymLinks
RewriteEngine on
RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ http://www.example.com/$1 [R=301,L]
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ http://www.example.com/$1 [R=301,L]
(+がついている)
RewriteEngine on
RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ http://www.example.com/$1 [R=301,L]
(Options FollowSymLinksがない)
の違いがあります。
それで以前の.htaccessは(いま使用中)
# For full documentation and other suggested options, please see
# http://svn.modxcms.com/docs/display/MODx096/Friendly+URL+Solutions
# including for unexpected logouts in multi-server/cloud environments
# and especially for the first three commented out rules
#php_flag register_globals Off
#AddDefaultCharset utf-8
#php_value date.timezone Asia/Tokyo
# Options +FollowSymlinks
RewriteEngine On
RewriteBase /
# Fix Apache internal dummy connections from breaking [(site_url)] cache
RewriteCond %{HTTP_USER_AGENT} ^.*internal\ dummy\ connection.*$ [NC]
RewriteRule .* - [F,L]
# Rewrite domain.com -> http://www.domain.com -- used with SEO Strict URLs plugin
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www.example\.com [NC]
RewriteRule (.*) http://example.com/$1 [R=301,L]
# Exclude /assets and /manager directories and images from rewrite rules
RewriteRule ^(manager|assets)/*$ - [L]
RewriteRule \.(jpg|jpeg|png|gif|ico)$ - [L]
# For Friendly URLs
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
# Reduce server overhead by enabling output compression if supported.
#php_flag zlib.output_compression On
#php_value zlib.output_compression_level 5
# For UTF-8
# php_flag output_buffering Off
# php_value output_handler none
# php_value default_charset UTF-8
# php_value mbstring.language japanese
# php_flag mbstring.encoding_translation On
# php_value mbstring.http_input auto
# php_value mbstring.http_output UTF-8
# php_value mbstring.internal_encoding UTF-8
# php_value mbstring.substitute_character none
# For EUC-JP
# php_flag output_buffering Off
# php_value output_handler none
# php_value default_charset EUC-JP
# php_value mbstring.language japanese
# php_flag mbstring.encoding_translation On
# php_value mbstring.http_input auto
# php_value mbstring.http_output EUC-JP
# php_value mbstring.internal_encoding EUC-JP
となっていましたが、# Reduce server overhead by enabling output compression if supported.以下の部分は恐らく不要だと思います。
それで最終的にwww無しとindex.html無しのURLに統一する場合はhtaccess.tplの編集は下記のようで良いのでしょうか
# http://modx.jp/docs/admin/htaccess.html
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
# MODXをサブディレクトリにインストールしている場合は「/modx」などに。
# Rewrite domain.com -> http://www.domain.com -- used with SEO Strict URLs plugin
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^example\.com [NC]
RewriteRule (.*) http://example.com/$1 [R=301,L]
RewriteEngine On
RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ http://example.com/$1 [R=301,L]
分かっている方から見れば適宜編集すればすぐできるのでしょうが、私なんかは数時間もこれに取り組んで難儀しています。出来れば、こうしたければ、ここだけ変更すれば良いですよ、みたいな長いテンプレートを添付して頂けると有難いのですが・・・・・
勝手な願望で申し訳ありません。
結論までが長いのですが、最後の.htaccessの記述が適性かどうか判断をお願い致します。