ドキュメントルートで次のようなものを試してください。
RewriteEngine On
# check if subdomain folder has the existing file, if so, serve it
RewriteCond %{HTTP_HOST} ^([^\.]+)\.domain\.co\.uk
RewriteCond %{DOCUMENT_ROOT}/%1%{REQUEST_URI} -f
RewriteRule ^(.*)$ /%1/$1 [L]
# check if subdomain folder has the existing directory WITH A TRAILING SLASH, if so serve it
RewriteCond %{HTTP_HOST} ^([^\.]+)\.domain\.co\.uk
RewriteCond %{DOCUMENT_ROOT}/%1%{REQUEST_URI} -d
RewriteRule ^(.*?)/$ /%1/$1/ [L]
# check if subdomain filder has the existing directory but missing trailing slash, redirect with it
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{HTTP_HOST} ^([^\.]+)\.domain\.co\.uk
RewriteCond %{DOCUMENT_ROOT}/%1%{REQUEST_URI} -d
RewriteRule ^(.*)$ /$1/ [R=301,L]
このメソッドは2つのことを行います。404の場合、内部で書き換えを試みないため、次の場所に移動するhttp://sub.domain.co.uk/this/path/does/not/exist/blah
と、次のような404メッセージは表示されません。URIがなかったという理由/sub/this/path/does/not/exist/blah
だけで、存在しません。 /this/path/does/not/exist/blah
t書き直されたため、基になるディレクトリ構造が公開されません。
2つ目は、おそらくDirectorySlash
オンになっていることです。つまり、次のようなディレクトリにアクセスした場合http://sub.domain.co.uk/this/path
、末尾のスラッシュがない場合、mod_dirはそのスラッシュをリダイレクトして追加しますが、URIが書き換えられ、次の場所にリダイレクトされるため、おそらく間違っていますhttp://sub.domain.co.uk/sub/this/path/
。を非表示にする正しいURIを使用して、末尾のスラッシュを先制的に追加しますsub
。