.htaccess 다른 하위 디렉터리를 깨지 않고 Wordpress 하위 디렉터리를 다시 작성합니다.
그래서 WordPress가 설치되어 /wp/
있지만 모든 WordPress URL이 루트 디렉토리에 나타나도록 다시 작성하고 싶습니다. 현재이 작업을 수행하고 있지만 (아래 참조) .htaccess
다른 하위 디렉터리가 손상되지 않도록 변경하고 싶습니다 .
예를 들어를 방문하려는 경우 www.example.com/images/image.png
현재 WordPress의 404 페이지로 다시 라우팅됩니다.
이것도 가능 .htaccess
합니까?
현재 코드 :
RewriteEngine on
#Wordpress
# Rewrites all URLS without wp in them
RewriteCond %{REQUEST_URI} !^/wp/
# Rewrites all URLS [Replace "example" with the actual domain, without the TLD (.com, .net, .biz, etc)]
RewriteCond %{HTTP_HOST} ^(www\.)?example\.
# Rewrite all those to insert /folder
RewriteRule ^(.*)$ /wp/$1 [L]
업데이트 : 시크릿 모드와 두 번째 브라우저로 MrWhite의 제안을 테스트했습니다. 효과가 없습니다. 새 .htaccess
파일 :
RewriteEngine on
#Wordpress
# Rewrites all URLS without wp in them
RewriteCond %{REQUEST_URI} !^/wp/
# Rewrites all URLS [Replace "example" with the actual domain, without the TLD (.com, .net, .biz, etc)]
RewriteCond %{HTTP_HOST} ^(www\.)?example\.
# Rewrite all those to insert /folder
RewriteRule ^(.*)$ /wp/$1 [L]
# Request does not map to an existing file
RewriteCond %{REQUEST_FILENAME} !-f
답변
기존 파일을 제외하는 조건을 추가해야합니다. 그렇지 않으면에 대한 요청 /images/image.png
이 자연스럽게 /wp/images/image.png
WordPress에서 다시 작성되고 404가 트리거됩니다 ( /wp/images/image.png
실제로 존재 하지 않는 한 ).
예를 들어 기존 규칙에 다음 조건을 추가합니다.
# Request does not map to an existing file
RewriteCond %{REQUEST_FILENAME} !-f
업데이트 : 이것은 작동하지 않는 것 같습니다. 여전히 WordPress 404 페이지로 이동
RewriteCond
지시문을 잘못된 위치에 넣었 습니다.
RewriteCond
지시문은 완전히 별개의 명령문이 아니며 다음 지시문에 적용 되는 조건 입니다 RewriteRule
. 그 자체로 RewriteCond
지시문은 아무것도하지 않습니다.
RewriteCond
지침 요구 (어디를) 이동 하기 전에RewriteRule
지침 :
RewriteEngine on
#Wordpress
# Rewrites all URLS without wp in them
RewriteCond %{REQUEST_URI} !^/wp/
# Rewrites all URLS [Replace "example" with the actual domain, without the TLD (.com, .net, .biz, etc)]
RewriteCond %{HTTP_HOST} ^(www\.)?example\.
# Request does not map to an existing file
RewriteCond %{REQUEST_FILENAME} !-f
# Rewrite all those to insert /folder
RewriteRule ^(.*)$ /wp/$1 [L]
또한 참조 .htaccess
를 위해 /wp
하위 디렉토리 의 "WordPress" 파일을 살펴보십시오 . 그것은 같은 종류의 일을합니다.
참고 : 다시 작성하지 않으려는 도메인이나 하위 도메인이 여러 개있는 경우가 아니면 호스트 이름 검사 (즉 RewriteCond
, HTTP_HOST
서버 변수 를 검사 하는 지시문)를 제거 할 수 있습니다 .