0

当サイトの多くのページでは、画像、css、javascriptファイルに古いサブドメインを使用しています。私は初心者の開発者からプロジェクトを継承しましたが、彼らは一般的なデザインテンプレートを使用していませんでした。結果は、コンテンツへの静的参照を含む数百ページになります。例は次のとおりです。

http://static.foo.bar/css/sample.css
http://static.foo.bar/brochure/css/sample.css
http://static.foo.bar/company/newsletter/js/common.js
http://static.foo.bar/images/version2/header.jpg

...そして他の何百もの場所。.htaccessファイルにこれらのそれぞれのルールを作成せずに、サブドメインではなくメインドメインをすべて指すようにする必要があります。それで:

http://static.foo.bar/css/sample.css 
should point to: 
http://www.foo.bar/css/sample.css

http://static.foo.bar/brochure/css/sample.css
should point to: 
http://www.foo.bar/brochure/css/sample.css

http://static.foo.bar/company/newsletter/js/common.js
should point to: 
http://www.foo.bar/company/newsletter/js/common.js

http://static.foo.bar/images/version2/header.jpg
should point to: 
http://www.foo.bar/images/version2/header.jpg

私はこれが可能であることを知っています。私はサーバーの人ではありません。どんな助けでも大歓迎です。

4

1 に答える 1

0

.htaccess次の内容でドキュメント ルートにファイルを作成します。

これをサーバー構成に追加してください。次%{HTTP_HOST}からチェックが機能しません.htaccess:

<IfModule mod_rewrite.c>
# bad matching: RewriteCond %{HTTP_HOST}   !^static\.foo\.bar [NC]
#
# correction, matching everything other than www.foo.bar :
RewriteCond %{HTTP_HOST}   !^www\.foo\.bar$ [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteRule ^/(.*)         http://www.foo.bar/$1 [L,R]
</IfModule>

http://httpd.apache.org/docs/2.0/misc/rewriteguide.html#urlを参照してください

更新: ただし、同じサーバーでホストされている場合は、追加するだけです。

ServerAlias static.foo.bar

www.foo.bar 構成に追加して、静的コンテンツも提供します。

フィードバックに基づく更新 #2:

これは.htaccessファイルで機能するはずです(私のPCで機能します)。これにより、に来るすべてのリクエストがリダイレクトされstatic.foo.bar/*ますwww.foo.bar/*

RewriteCond %{HTTP_HOST}    ^static\.foo\.bar [NC]
RewriteRule ^(.*)$          http://www.foo.bar/$1 [R,L]

いいえ、ServerAlias コマンドは VirtualHost 構成からのみ機能します。

http://httpd.apache.org/docs/2.2/mod/core.html#serveralias

于 2012-04-09T13:13:24.837 に答える