1

私のウェブサイトには次の構造があり、すべてのトラフィックをサブドメインにリダイレクトする必要があります

構造:

domain.com/subdomain/
                 .../folder1/folder/1.txt
                 .../folder1/folder/2.txt
                 .../folder2/folder/1.txt
                 .../folder2/folder/1.txt
                 .../index.php

index.phpまたは(domain.com/subdomain/)を除くすべてのトラフィックをサブドメインにリダイレクトしたい

例:

domain.com/subdomain/folder1/folder/1.txt    --->    subdomain.domain.com/folder1/folder/1.txt
domain.com/subdomain/folder1/folder/2.txt    --->    subdomain.domain.com/folder1/folder/1.txt

だが

domain.com/subdomain/index.php    --->    No redirect
domain.com/subdomain/    --->    No redirect

これは私が思いついたものです:

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)$ http://subdomain.domain.com/$1 [NC]

これはすべてのリクエストで機能しますが、このRewriteRuleから/とindex.phpの両方を除外したいと思います

ありがとう!

4

1 に答える 1

1

そこにあるものよりも少し多く必要になります。最初に でドメインを確認する必要がありますRewriteCond。パターン^subdomain/?(index\.php)?$は、サブドメイン ルートへの要求、index.phpまたは/. subdomainindex.php技術的には、中間のない無効にも一致します/が、とにかく 404 になります。

RewriteEngine On
# If the requested domain isn't already the subdomain...
RewriteCond %{HTTP_HOST} !^subdomain\. [NC]
# Rewrite it to the subdomain
# unless it is a request for index.php or /
RewriteRule ^subdomain/?(index\.php)?$ - [L]
RewriteRule ^subdomain/(.*) http://subdomain.com/$1 [L,R=301,NC]
于 2012-12-29T13:29:14.253 に答える