ワイルドカードサブドメインをオンにしていますが、これを書くのに必要な範囲で mod_rewrite を知りません。www 以外のものはメイン サイトに移動し、それ以外のサブドメインは /script/index.php?username=$username に移動するようにする方法を誰か教えてもらえますか?
1783 次
1 に答える
1
$ username変数はどこから来るのでしょうか?
メインサイトのURLがhttp://www.example.com/main_site.phpであり、これを外部のディレクトリコンテキスト(つまり、.htaccessでも<Directory>ディレクティブでもない)で使用しているとします。.htaccessにある場合は、先頭の/を削除します(たとえば、main_site.phpだけにします)。
明確でない変数がたくさんあるので、これはすぐには機能しないと思います(ユーザー名はどこから来たのですか?、リクエストの残りの部分をどうするか、パラメーターとして渡しますか?、これはhtaccessまたはメイン構成ですか?)が、うまくいけば、あなたにアイデアを得るでしょう:
#Turn on the rewrite engine
RewriteEngine On
#Check accessed domain, if it's either www.example.com or
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC,OR]
#example.com
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
#and the requested URL does not contain script you'll be accessing to avoid looping
RewriteCond %{REQUEST_URI} !main_site.php
#Then we tell that everything matching the above will go to main_site.php
RewriteRule ^ /main_site.php [L]
#If the request is not asking for main_site.php nor index.php
RewriteCond %{REQUEST_URI} !main_site.php
RewriteCond %{REQUEST_URI} !index.php
#We go to /script/index.php (username will be empty, becase we don't know
#where to get it from)
RewriteRule ^ /script/index.php?username=$username [L]
于 2008-10-23T04:20:16.983 に答える