2016-10-25 9 views
0

私は書き直しルールに強くはありません。私はすでに Wildcard .htaccess rewrite subdomian to a subdirectory with subdomain as GET variable(私の質問)と.htaccess rewrite: subdomain as GET parameter and filepath afterdomain intacthttps://serverfault.com/questions/214512/を通過しましたが、私の問題の解決策を見つけることができませんでした。私は私の要求が可能かどうかもわかりませんが、私は依然として確かめることを依頼しています。私はこれが必要なのはなぜ
ワイルドカード.htaccessはGET変数としてサブドメインとホワイトリストドメインを書き換えます

http://example.com    -> https://www.example.com    [redirect] 
http://example.com/dir/?key=12 -> https://www.example.com/dir/?key=12 [redirect] 
https://example.com   -> https://www.example.com    [redirect] 
https://example.com/dir/?key=12 -> https://www.example.com/dir/?key=12 [redirect] 
http://xyz.example.com   -> https://xyz.example.com    [redirect] 
http://www.xyz.example.com  -> https://xyz.example.com    [redirect] 
https://www.xyz.example.com -> https://xyz.example.com    [redirect] 
https://xyz.example.com  -> https://www.example.com/whitelabel/?user=xyz [proxy] 
https://xyz.example.com/profile.php -> https://www.example.com/whitelabel/profile.php?user=xyz   [proxy] 
https://xyz.example.com/dir/settings.php -> https://www.example.com/whitelabel/dir/settings.php?user=xyz [proxy] 
https://xyz.example.com/dir/settings.php?par=val -> https://www.example.com/whitelabel/dir/settings.php?user=xyz&par=val [proxy] 
http://example.org    -> https://www.example.com/whitelabel/?domain=abc.example.org    [proxy] 
https://www.example.org  -> https://www.example.com/whitelabel/?domain=example.org     [proxy] 
https://example.org?param=val -> https://www.example.com/whitelabel/?domain=example.org&param=val  [proxy] 
https://example.org/dir1/dir2?param=val -> https://www.example.com/whitelabel/dir1/dir2?domain=example.org&param=val [proxy] 


結果を希望しますか?登録されたすべてのユーザーは、デフォルトでサブドメインを取得しますが、ドメインを持っている場合は、そのドメインを専用のIPにポイントできます。私は各サブドメインまたはドメインに異なる内容を表示する必要があります。
私はすでにhttp-> httpsを行い、必要な場所にwwwを追加しました。私はGETパラメータとしてサブドメインも渡しました。それぞれのコードは個別にうまく動作しますが、組み合わせると機能しません。たぶん、それはルールの順序と関係があります。とにかく、私の.htaccessです

<IfModule mod_rewrite.c> 
RewriteEngine On 

RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$ 
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [L,R=301] 

RewriteCond %{HTTPS} off 
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L] 

RewriteCond %{HTTP_HOST} ^((?!www\.)[^.]+)\.toours\.com$ 
RewriteRule^https://www.toours.com/whitelabel%{REQUEST_URI}?user=%1 [QSA,L,P] 
RewriteRule (.*)/whitelabel/(.*) $1/$2 [L] 
</IfModule> 

これはちょっとした内部エラーです。これはあなたの道のほとんどを取得する必要があります

+0

'RewriteRule(。*)/ whitelabel /(.*)$ 1/$ 2 [L]'行をコメントして再テストします。 – anubhava

+0

はまだ同じエラーです。 @anubhavaに参加してくれてありがとう。私はあなたのために連絡することを考えていた。あなたの評判はあなたの前にあります。 –

+0

ありがとうございます。この時点でApache error.logをチェックして、なぜ500が来るのかを確認する必要があります。 – anubhava

答えて

0

<IfModule mod_rewrite.c> 
RewriteEngine On 

# ensure www when no subdomain 
RewriteCond %{HTTP_HOST} ^example\.com$ 
RewriteRule .* https://www.%0/$0 [L,R=301] 
# ensure no www when user subdomain 
RewriteCond %{HTTP_HOST} ^www\.([^.]+\.example\.com)$ 
RewriteRule .* https://%1/$0 [L,R=301] 
# ensure https for all (you will have to add users' own domains to your SSL cert) 
RewriteCond %{HTTPS} !=on 
RewriteRule .* https://%{HTTP_HOST}/$0 [L,R=301] 

# set env vars if user subdomain 
RewriteCond %{HTTP_HOST} ^(?!www\.)([^.]+)\.example\.com$ 
RewriteRule^- [E=USERID:%1,E=USERPARAM:user] 
# set env vars if user own domain 
RewriteCond %{HTTP_HOST} ^.+(?<!\.example\.com)$ 
RewriteRule^- [E=USERID:%0,E=USERPARAM:domain] 

# user main page pretty URLs (removed ".php" from the public URLs) 
RewriteCond %{ENV:USERID} .+ 
RewriteRule ^$ whitelabel/?%{ENV:USERPARAM}=%0 [L,B,QSA] 
RewriteCond %{ENV:USERID} .+ 
RewriteRule ^profile$ whitelabel/profile.php?%{ENV:USERPARAM}=%0 [L,B,QSA] 
RewriteCond %{ENV:USERID} .+ 
RewriteRule ^dir/settings$ whitelabel/dir/settings.php?%{ENV:USERPARAM}=%0 [L,B,QSA] 
RewriteCond %{ENV:USERID} .+ 
# put any other whitelabel rules before this, so any remaining URLs that are not on your main domain get a custom 404 page 
RewriteRule^whitelabel/dir/404.php?%{ENV:USERPARAM}=%0 [L,B,QSA] 

# place any other pretty URLs for main domain here, probably rewrite all non-file requests to a single file and route from there 
</IfModule> 

クエリ文字列は、置換は1つを得ていないデフォルトで追加されます、と私はそれが持っているQSAを追加しました。

正規のユーザーが所有しているドメインにリダイレクトする方法についてよくわかりません。

関連する問題