アプリケーションを構築していますが、サブドメイン「x」をマップしたいのですexample.com/_sub/x/
が、フォルダー「x」がフォルダー「_sub」に存在する場合に限ります。そうでない場合は、example.comを表示してほしい。以下は機能しますが、ファイルまたはフォルダーがフォルダーx内にも存在する場合に限ります。
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(.*).example.com [NC]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ http://example.com/_sub/%1/$1 [L]
</IfModule>
これは別の見方です。
doesNotExist.example.com -> example.com
test.example.com -> test.example.com
example.com -> example.com
これが私の更新されたコードです。
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
#If the file and directory exists
RewriteCond %{HTTP_HOST} ^(.*).example.com [NC]
RewriteCond %{DOCUMENT_ROOT}/_sub/%1/ -d
RewriteCond %{DOCUMENT_ROOT}/_sub/%1/$1 -f
RewriteRule ^(.*)$ http://example.com/_sub/%1/$1 [P]
#If the directory exists but the file does not
RewriteCond %{HTTP_HOST} ^(.*).example.com [NC]
RewriteCond %{DOCUMENT_ROOT}/_sub/%1/ -d
RewriteCond %{DOCUMENT_ROOT}/_sub/%1/$1 !-f
RewriteRule ^(.*)$ http://example.com/_sub/%1/404.html [P]
</IfModule>