#StackBounty: #2013 #managed-navigation #url-rewriting Rearrange managed navigation but keep existing URLs

Bounty: 50

We have a site that has been used across our company for a couple of years. It uses managed navigation to create friendly urls and includes a lot of published content and several different discussion forums. For us it has been a very successful site with a lot of usage.

The original navigation menu at the top of the page was fairly shallow with just a few choices that lead to landing/query pages that then went further into the content. This was a specific decision made early in the design process and has worked okay, but in our user surveys we’ve heard that we need to improve the navigation.

What we have

For example the site caters to some different groups without our structure — the admin group, the user group, and general interest group. Currently the top navigation menu just has a menu item for Groups and the groups landing page shows a bit of information about the three actual groups.

  • Groups (in nav and friendly url)
    • Admins (friendly url only)
    • Users (friendly url only)
    • General topics (friendly url only)

Many people have bookmarked the friendly urls to their specific group(s) and we have a lot of collateral materials with links directly to friendly urls like site/groups/admins or site/groups/admins/discussions.

What we want to do

Our interviews with users has suggested that we switch to more of a mega-menu style with headings and rearrange some of the orders. We want to rearrange and repin existing nodes to new places, but we want to keep the existing urls because they have been popular and used for years.

  • Get involved (heading only non-clickable)
    • Groups (heading only non-clickable)
      • Admins (Link to /site/groups/admins)
      • Users (Link to /site/groups/users)
      • General interest (Link to /site/groups/general)
      • All groups (Link to /site/groups)
    • Some new ways to get involved
      • So on and so forth

The new menu items are no problem because they are new things and we can easily add. The issue is with rearranging the exiting navigation terms. For example groups used to be a first level node, but now it is organized down two levels. That means the managed navigation is trying to put the page at site/involved/groups/admins.

I realized I could go into the term store and configure the friendly url. I tried to set the value of the Get involved node to be blank and it did let me do it.

enter image description here

The navigation updated and when I hover over the link in the menu it does show the url I want site/groups/admins, but when I click the link in the nav it gives me a page not found error. So I don’t think that will actually work.

Another solutions I’m thinking of, is to create a whole shadow navigation that keeps the original urls, but hides them from the nav, and then a new set of nodes to show in the nav. These would provide the needed structure at new urls, and then all those new urls would point to a redirect page that would go to the old known urls. Seems very labor intensive and likely to break or be difficult to keep up.

Any other suggestions on how we can rework our nav, but keep existing urls? (We are only site collection admins, no access to central admin or that kind of stuff).


Get this bounty!!!

#StackBounty: #wp-admin #url-rewriting #redirect #dashboard Prevent /wp-admin/ from redirecting to homepage?

Bounty: 50

I have copied a wordpress instance from production to my local. After getting the public side of the site up – public homepage, pages, and blog posts -, I cannot access /wp-admin/ because that url always redirects to the / homepage. I have tried:

  • Updating the siteurl and home to “tk.local” (homepage and posts work fine)
  • Implementing a local self-signed ssl cert (in case it was an https problem.)
  • Switching themes (switched fine, problem still persists)
  • Setting debug constants in wp-config.php
  • Removing debug constants in wp-config.php

Here is a curl of wp-admin:

curl -Ik https://tk.local/wp-admin/
HTTP/1.1 301 Moved Permanently
Server: nginx/1.16.0
Date: Wed, 24 Jul 2019 17:27:39 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
X-Powered-By: PHP/5.6.40
X-Redirect-By: WordPress
Location: https://tk.local/
Last-Modified: Wed, 24 Jul 2019 17:27:39 GMT
Expires: Wed, 24 Jul 2019 18:27:39 GMT
Pragma: public
Cache-Control: max-age=3600, public
ETag: "d41d8cd98f00b204e9800998ecf8427e"
Strict-Transport-Security: max-age=63072000; includeSubdomains
X-Frame-Options: DENY
X-Content-Type-Options: nosniff
X-uri: /wp-admin/

Obviously on the production copy the wp-admin url works. Throughout it all, it 301 redirects from https://tk.local/wp-admin to https://tk.local/
How can I prevent it from redirecting?


Get this bounty!!!

#StackBounty: #nginx #redirect #url-rewriting Nginx redirect rule has no affect

Bounty: 50

Trying to do a simple redirect:

rewrite https://url.example.com(.*) https://example.com/plugins/url permanent;

Anytime url.example.com is hit, I want it to redirect to that specific path.

EDIT:

Will try to explain this better, as I’m trying to redirect to a specific domain from another.

server {
    server_name example.com plugin.example.com;
    root /home/www/example.com/public;
}

I see the location used for redirects such as:

location / {
    try_files $uri $uri/ /index.php?$query_string;
}

But not sure how to use it in my case, which is to change plugin.example.com to example.com/plugin.

For example:

http://plugin.example.com
https://plugin.example.com
https://plugin.example.com/blah
https://plugin.example.com/blah/more

All of these should redirect to:

https://example.com/plugin


Get this bounty!!!

#StackBounty: #permalinks #filters #url-rewriting Remove the Parent category from the permalink but leave the child category

Bounty: 50

I had a site with a url structure like

example.com/news/story-1
example.com/news/local/story-2
example.com/food/tacos/story-3

Now it’s been moves to a multisite, with /news/ and /food/ as the site subfolders.

Within those sub-sites, the top level category is News or Food, respectively. So if the permalink is set to /%category%/%postname%/, the permalink come out as

example.com/news/news/local/story-title
example.com/food/food/tacos/story-title

In order to remove the category that’s a duplicate of the site subfolder, I added this to functions.php:

add_filter( 'post_link', 'remove_parent_category', 10, 3 );
    function remove_parent_category( $permalink, $post, $leavename ) {
        $permalink_array = explode("/", $permalink);
        $clean_permalink = array_unique($permalink_array);
        $new_permalink = implode("/", $clean_permalink);
        return $new_permalink;
    }  

This works, giving me back

example.com/news/local/story-2
example.com/food/tacos/story-3

and the ability to navigate to

example.com/news/
example.com/news/local
etc.

However posts that are in the top level category now 404 (which I suppose is to be expected) because their url is now

example.com/news/story-1

(which is what I want).

From what I’m gathering I think I need to use either pre_post_link or a rewrite rule to treat those top level posts as if my permalink structure is just %postname%/, but that’s where I’m stuck.


Get this bounty!!!

#StackBounty: #php #json #wordpress #api #url-rewriting WordPress – How does one make a URL return dynamic JSON with custom Content Type?

Bounty: 50

Some background first, I’m trying to follow the directions here:

https://developer.apple.com/library/archive/documentation/General/Conceptual/AppSearch/UniversalLinks.html#//apple_ref/doc/uid/TP40016308-CH12-SW1

to get universal links working with my website for iOS devices. My wordpress site is in a shared hosting environment, therefore I do NOT have access to the server or any root files. I placed the file at the root of my site (httpdocs) and when I navigate to the page it does not load. In googling around, I found a stackoverflow post stating you had to config the server to let it know to serve up that file with a content type of “application/pkcs7-mime” (Config apple-app-site-association file with wordpress). As mentioned I do not have access to that.

I have a subdomain which is a microsoft web api project that I am very familiar with. I made an endpoint for “apple-app-site-association” and dynamically built the json response in code and set the content type and returned it. This ended up working and Apple detects it and everything. This is interesting as I do NOT need a file on my server as I generate it on the fly, and I don’t need to change anything server wise.

The issue however is I need the main site domain to be the universal link, not the windows subdomain. The main site is wordpress. I’m thinking if may be possible to do the same thing in wordpress where I navigate to mydomain.com/apple-app-site-association and I generate the json and content-type on the fly and serve it up.

I’ve never done any coding with wordpress and don’t even know where to start.

If possible I would like clear direction in the following:

Making mydomain.com/apple-app-site-association lead to a custom function or page that serves up json.
Have code that makes the json get served up dynamically.
Have code that sets the content-type of the response to “application/pkcs7-mime”.
Of course if someone knows how to solve the file not being served no a shared server without this method, I’m open to that as well. From what I can see, this may be the only way assuming this can be done.


Get this bounty!!!

#StackBounty: #multisite #url-rewriting #rewrite-rules #add-rewrite-rule Custom rewrite rule sends 404 header on multisite

Bounty: 50

I have a custom rewrite rule which rewrites /wp-content/themes/my-theme/manifest.json to /index.php?manifest=true. This generates some JSON code for progressive web app functionality, and generally works great.

On a multisite install, however, the manifest loads correctly, but still sends a 404 header. I verified that this specific theme does work fine with a normal WordPress site, but in a multisite install, it always seems to send the 404 header.

enter image description here

Some notes:

  • I’ve tried using status_header(200), and header("HTTP/1.1 200 OK") manually, but neither of those make a difference
  • I’ve tried setting $wp->is_404 to false, but that does nothing
  • I’ve flushed the permalinks, but that does nothing

Rewrite Rule PHP:

// set up rewirte rules for PWA functionality
function fvpd_pwa_rewrite_rules() {
    add_rewrite_endpoint("manifest", EP_NONE);
    add_rewrite_rule(substr(parse_url(get_template_directory_uri(), PHP_URL_PATH), 1) . "/manifest.json$", "index.php?manifest=true", "top");
}
add_action("init", "fvpd_pwa_rewrite_rules");

manifest.json PHP:

// construct a manifest when the user visits {theme_folder}/manifest.json
function fvpd_construct_manifest() {
    if (get_query_var("manifest")) {
        header("Content-Type: application/json");

        $name             = fvpd_get_field("full_name", "pwa");
        $short_name       = fvpd_get_field("short_name", "pwa");
        $background_color = fvpd_get_field("background_color", "pwa");
        $theme_color      = fvpd_get_field("theme_color", "pwa");

        $manifest = array(
            "start_url"        => "/",
            "display"          => "standalone",
            "name"             => $name ? $name : "Fox Valley Park District - DEV",
            "short_name"       => $short_name ? $short_name : "FVPD",
            "background_color" => $background_color ? $background_color : "#E58F1A",
            "theme_color"      => $theme_color ? $theme_color : "#E58F1A",
            "icons"            => array(
                array(
                    "src"   => get_theme_file_uri("assets/media/android/splash-icon-512x512.png"),
                    "type"  => "image/png",
                    "sizes" => "512x512",
                ),
                array(
                    "src"   => get_theme_file_uri("assets/media/android/launcher-icon-192x192.png"),
                    "type"  => "image/png",
                    "sizes" => "192x192",
                ),
                array(
                    "src"   => get_theme_file_uri("assets/media/android/launcher-icon-144x144.png"),
                    "type"  => "image/png",
                    "sizes" => "144x144",
                ),
                array(
                    "src"   => get_theme_file_uri("assets/media/android/launcher-icon-96x96.png"),
                    "type"  => "image/png",
                    "sizes" => "96x96",
                ),
                array(
                    "src"   => get_theme_file_uri("assets/media/android/launcher-icon-72x72.png"),
                    "type"  => "image/png",
                    "sizes" => "72x72",
                ),
                array(
                    "src"   => get_theme_file_uri("assets/media/android/launcher-icon-48x48.png"),
                    "type"  => "image/png",
                    "sizes" => "48x48",
                ),
            ),
        );

        echo json_encode($manifest); exit;
    }
}
add_action("wp", "fvpd_construct_manifest");

URL in questions:

https://www.foxvalleyparkdistrict.org/wp-content/themes/fox-valley-park-district/manifest.json

This does not affect my other custom rewrite, which points /offline/ to load a custom template.

https://www.foxvalleyparkdistrict.org/offline/

Why is the 404 header being sent, and how can I fix it?


Get this bounty!!!

#StackBounty: #seo #htaccess #url-rewriting #amp Is it safe to do a htaccess rewrite for mobile traffic to amp pages?

Bounty: 50

I have a requirement to use the same URL for both desktop and mobile devices. On mobile, I want to serve amp HTML while on the desktop I want to render normal HTML. In such case is it safe (from SEO and Adwords perspective) to detect the user agent and issue a rewrite rule to load amp HTML (from an internal URL) for mobile?

(I know of “link canonical” method of implementing amp for mobile devices. But in my case I need to use a common URL.)


Get this bounty!!!