2

私のアプリでは、次のような多くの画像の src があります。

パス/他のパス/my-image.jpg

これには時間がかかり、ファイル構造の一部が外部に公開される可能性があります。

特定のファイル拡張子をディレクトリにリダイレクトするには、.htaccess で何ができますか?

つまり、私のイメージ src は単に "my-image.jpg" であり、.htaccess はそれが .jpg ファイルであることを認識し、"my-image.jpg" が存在するフォルダー "www.site.com/my-jpgs/" にリダイレクトします。したがって、画像をロードします。

現時点で私が持っているものは次のとおりです。

    Options +FollowSymLinks
IndexIgnore */*
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/importers
RewriteCond %{REQUEST_URI} !\.(gif|jpg|png)$

RewriteRule ^(.*)$ public_html/index.php

RewriteBase /

# Ignore rule if the real path exists, use that instead.
RewriteCond %{REQUEST_FILENAME} !-f 
# Only use the filename and extension.
RewriteRule (.[^/]*)\.(gif|jpg|png) public_html/images$1.$2 [R,L]

ブラウザが次のような2つのリクエストを行うことを除いて、私はそれをうまく機能させています。

リクエスト URL: http://www.view.com/activity/enquiry/dropdown-btn.gif

リクエスト URL: http://www.view.com/public_html/images/dropdown-btn.gif

2 番目は正しいですが、最初の間違った要求を行わないようにするにはどうすればよいですか?

4

1 に答える 1

0

.htaccess. Your problem is incorrect ordering of your rule. You need to move last rule to the top just belowRewriteEngine On line to have external redirect before sending everything off toindex.php`では、書き換えルールの順序付けが非常に重要です。

Options +FollowSymLinks
IndexIgnore */*
RewriteEngine On
RewriteBase /

# Ignore rule if the real path exists, use that instead.
RewriteCond %{REQUEST_FILENAME} !-f 
# Only use the filename and extension.
RewriteRule ^(?:[^/]+/)*([^.]+\.(?:gif|jpe?g|png))$ images/$1 [R,L,NC]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/importers
RewriteCond %{REQUEST_URI} !\.(gif|jpe?g|png)$
RewriteRule ^ index.php [L]
于 2013-10-03T16:41:27.227 に答える