1

私のベースディレクトリには、たくさんのフォルダーがあります。これらのフォルダーをサブディレクトリに入れたいと思います。

domain.com/test/test.html

ファイル構造は次のようになります。

domain.com/subdir/test/test.html

それでも同じ URL にあります: domain.com/test/

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteCond %{REQUEST_URI} !^/subdir/
RewriteRule ^(.*)$ /subdir/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

ここで別の回答からコピーするとそれが行われますが、ベースディレクトリへの他のリクエストも停止します。

サブディレクトリ内のフォルダー名の一致を確認し、それが存在するかどうか、またはベースディレクトリから提供されていないかどうかを確認する必要があります。

4

1 に答える 1

0

これを試して:

RewriteEngine on

# these conditions are optional, they're to make sure you don't clobber a legit request
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# these conditions aren't optional, they check to see if the requested file/dir exists inside /subdir
RewriteCond %{DOCUMENT_ROOT}/subdir%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}/subdir%{REQUEST_URI} -d

# rewrite
RewriteRule ^(.*)$ /subdir/$1 [L]
于 2012-09-28T07:37:43.310 に答える