Wordpress 기반 외부에 있는 URL로 다시 쓰기
내 워드프레스 블로그는 다음 위치에 설치됩니다.domain.com/blog서브페이지가 있는 페이지가 있는데, 그 페이지 구조는domain.com/blog/page그리고.domain.com/blog/page/subpage.
방문자가 다음 장소에 갈 수 있도록 하고 싶다.domain.com/subpage의 내용을 확인합니다.domain.com/blog/page/subpage이 URL로 외부로 리다이렉트 되지 않기 때문에 워드프레스 퍼멀링크 개서를 피할 수 있습니다.
나는 그것을 사용해봤어요.RewriteRule ^subpage$ /page/subpage [L]그리고 콘텐츠는 제공되고 있지만, URL은domain.com/blog/page/subpage(워드프레스 퍼멀링크가 그런 것 같아요)
.htaccess:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
// tried inserting my code here.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
# END WordPress
편집:
이 로그는 페이지 방문 시 액티비티를 보여줍니다.
ip - - [19/Jun/2012:14:03:53 -0400] "GET /subpage/ HTTP/1.1" 301 - "http://domain.com/referrer/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:13.0) Gecko/20100101 Firefox/13.0.1"
ip - - [19/Jun/2012:14:03:53 -0400] "GET /blog/page/subpage/ HTTP/1.1" 200 20022 "http://domain.com/referrer/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:13.0) Gecko/20100101 Firefox/13.0.1"
그리고 여기 내 root.htaccess가 있습니다.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^subpage/?$ /blog/page/subpage/ [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
RewriteCond %{HTTP_HOST} ^domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.domain.com$
Wordpress를 사용하는 동안 htaccess에 몇 가지 규칙을 추가하는 것은 항상 까다롭습니다.대신 rewrite API를 사용해야 합니다.
먼저 이 코드를 다음에 넣습니다./wp-content/themes/CURRENT_THEME_ACTIVATED/functions.php:
function my_custom_page_rewrite_rule()
{
add_rewrite_rule('^subpage/?', 'index.php?pagename=page/subpage', 'top');
}
add_filter('init', 'my_custom_page_rewrite_rule');
비고: 페이지 수준을 지정해야 합니다.pagename파라미터를 지정하지 않으면 URL이 변경됩니다.
그런 다음 워드프레스에게 새로운 규칙을 고려해야 한다고 말해야 합니다.이를 위해서는 관리 패널로 이동합니다.Settings>Permalinks> 을 클릭합니다.Save버튼을 클릭합니다.자, 이제 다음 페이지로 이동하실 수 있습니다.domain.com/blog/subpage의 내용을 확인합니다.domain.com/blog/page/subpage(url은 변경되지 않습니다).
마지막으로, 만약 여러분이domain.com/subpage도달 가능. 루트 폴더에 htaccess를 추가하고 다음 코드를 입력해야 합니다.
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ blog/$1 [L]
그리고... 그게 다야에 접속할 수 있습니다.domain.com/subpage원하는 걸 얻을 수 있을 거야
언급URL : https://stackoverflow.com/questions/11090088/rewrite-to-url-outside-of-wordpress-base
'source' 카테고리의 다른 글
| WP_DEBUG_LOG가 true로 설정되어 있으면 debug.log에 디버깅 출력이 표시되지 않습니다.이유는 무엇입니까? (0) | 2023.02.07 |
|---|---|
| POST JSON이 415 Unsupported media type, Spring 3 mvc로 실패합니다. (0) | 2023.02.07 |
| WordPress 링크 모두 이중 URL로 리디렉션 (0) | 2023.02.07 |
| 워드프레스 카테고리.php 페이지 번호 404 오류 (0) | 2023.02.07 |
| 게시물을 클릭하면 WordPress의 데이터베이스에서 쿼리된 값이 전송되도록 하는 방법 (0) | 2023.02.07 |