2013-10-24 6 views
1

.htaccess을 사용하여 하위 디렉토리를 하위 도메인으로 리디렉션하고 싶습니다. 현재 코드 :하위 디렉토리를 .htaccess의 하위 도메인으로 리디렉션

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
RewriteCond %{HTTP_HOST} ^(www.)?sub.example.com$ 
RewriteRule ^(/)?$ subdirectory [L] 
</IfModule> 

이 코드는 sub.example.com/subdirectory으로 리디렉션됩니다. 새 URL에서 /subdirectory을 어떻게 제거합니까?

답변

1

장소 다른 모든 규칙 전에 상단에이 규칙 :

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC] 
RewriteRule ^subdirectory/(.*)$ http://www.sub.example.com/$1 [L,NC,R=301] 

전체 htaccess로 : 당신의 대답에 대한

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC] 
RewriteRule ^subdirectory/(.*)$ http://sub.example.com/$1 [L,NC,R=301] 

RewriteCond %{HTTP_HOST} ^(www\.)?sub\.example\.com$ [NC] 
RewriteCond %{REQUEST_URI} !(jpe?g|gif|bmp|png|tiff|css|js)$ [NC] 
RewriteRule !subdirectory subdirectory%{REQUEST_URI} [NC,L] 

RewriteRule ^index\.php$ - [L] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
</IfModule> 
+0

감사합니다! 이제 sub.example.com에 액세스 할 수 있지만 두 가지 문제가 발생합니다. Wordpress가 엉망입니다. 여기 스크린 샷이 있습니다. http://s8.postimg.org/5rupjqwdv/image.png - 템플릿 구조가 없습니다. 스타일 등. 두 번째 문제는 이제 example.com/subdirectory가 www.subexample.com으로 연결되며 www가 누락 된 URL이라는 점입니다. 어쩌면 www가 아닌 ​​www로 리디렉션하면이 문제가 해결됩니까? –

+0

스타일의 경우 JS 등의 솔루션은 간단합니다. CSS, js, 이미지 파일 중 상대적인 경로가 아닌 절대 경로 만 사용하면됩니다. 즉,이 파일의 경로가'http : //'또는 슬래시'/'로 시작해야 함을 의미합니다. – anubhava

+0

또한 'www.subexample.com'도 Wordpress에 의해 관리되는지 아닌지 알고 있습니까? – anubhava

관련 문제