Opened 5 years ago
Closed 3 years ago
#6298 closed defect (bug) (duplicate)
Canonical redirect broken on static front page
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Optimization | Version: | 2.5 |
| Severity: | major | Keywords: | |
| Cc: |
Description
Create a static page, 'Test', publish and browse the page.
In a separate window, browse settings / reading, set this page as the static front page.
Return to the initial window, refresh.
Behavior produced: WP displays the page as it normally would.
Expected behavior: WP redirects to get_option('home');
Change History (7)
the above code has a tiny bug: the is_paged() case also needs to be processed.
D.
- Owner changed from markjaquith to Denis-de-Bernardy
- Status changed from new to accepted
- Owner Denis-de-Bernardy deleted
- Status changed from accepted to assigned
comment:6
markjaquith — 3 years ago
- Milestone changed from 2.9 to 3.0
Note: See
TracTickets for help on using
tickets.

Fix:
if ( is_front_page() ) { $home_url = get_option('home'); $home_path = parse_url($home_url); $home_path = $home_path['path']; if ( rtrim($_SERVER['REQUEST_URI'], '/') != rtrim($home_path, '/') ) { header('HTTP/1.1 301 Moved Permanently'); header('Status: 301 Moved Permanently'); #var_dump(rtrim($_SERVER['REQUEST_URI'], '/'), rtrim($home_path, '/')); wp_redirect($home_url); die; } }