2012-03-07 6 views
0

ローカルホストとリモートホストの両方がルートをサブディレクトリにリダイレクトする方法を教えてください。htaccessは2つのホストをサブディレクトリにリダイレクトする方法

ローカルホスト:domain.localhost
リモートホスト:domain.com
サブディレクトリ:サブディレクトリ

domain.localhost -> domain.localhost/subdir/<br> 
domain.localhost/ -> domain.localhost/subdir/<br> 
domain.com-> domain.com/subdir/<br> 
www.domain.com -> www.domain.com/subdir/<br> 

Options +FollowSymLinks 
DirectoryIndex questions.php 
RewriteEngine on 

RewriteCond %{HTTP_HOST} ^domain\.localhost$ 
RewriteRule ^(.*)$ http://domain\.localhost/subdir/$1 [R=301,L] 

RewriteCond %{REQUEST_URI} ^/$ 
RewriteRule (.*) http://www.domain.com/subdir/ [R=301,L] 
+0

私はすべてのソリューションを試しましたが、残念ながら期待どおりに機能しませんでした。すべてのあなたの答えのおかげでみんな。 – Codex73

答えて

0

ドメイン名を指定する必要はありません書き換えルール内:

RewriteCond $0 !^subdir 
RewriteRule (.*) /subdir/$1 [L] 

(お使いのブラウザが最初のキャッシュクリアす​​ることを忘れないでください)

0

あなたは完全なURLを指定しない場合、Modの書き換えは、リクエストのドメインにそれが相対になります。言い換えれば、RewriteRule ^(.*)$ /subdir$1 [R=301,L]はリダイレクトしますhttp://domain.localhost/blah-blahhttp://domain.localhost/subdir/blah-blah

あなたの設定は、単一のRewriteRuleに凝縮することができます

Options +FollowSymLinks 
DirectoryIndex questions.php 
RewriteEngine on 

RewriteCond %{REQUEST_URI} !^/subdir 
RewriteRule ^(.*)$ /subdir$1 [R=301,L] 

のRewriteRuleパターンマッチが初期/、すなわち/何とか-何とかが含まれますので、書き換え/subdir$1は、リダイレクトが二重スラッシュを引き起こさないようにします。これらの原則のために

1

:それは "/" なしで試して動作しない場合

Options +FollowSymLinks 
DirectoryIndex questions.php 
RewriteEngine on 

# domain.localhost -> domain.localhost/subdir/ 
RewriteCond %{HTTP_HOST} ^domain\.localhost$ 
RewriteRule (.*) /subdir/$1 [QSA,L] 

# domain.com -> domain.com/subdir/ 
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ 
RewriteRule (.*) /subdir/$1 [QSA,L] 

Options +FollowSymLinks 
DirectoryIndex questions.php 
RewriteEngine on 

# domain.localhost -> domain.localhost/subdir/ 
RewriteCond %{HTTP_HOST} ^domain\.localhost$ 
RewriteRule (.*) /subdir$1 [QSA,L] 

# domain.com -> domain.com/subdir/ 
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ 
RewriteRule (.*) /subdir$1 [QSA,L] 
をここで

domain.localhost -> domain.localhost/subdir/ 
domain.localhost/ -> domain.localhost/subdir/ 
domain.com-> domain.com/subdir/ 

www.domain.com -> www.domain.com/subdir/ 

が正確rewriterulesあります


NB:[R]ディレクティブでリダイレクトする必要はありません。ドメイン全体を正確に表示する必要はありません。

関連する問題