domain.com/died-persons/2024/
where ‘died-persons’ is a static page with a table of contents (list of years) and ‘2024’ is a virtual directory (variable) which I manage by a rewrite rule. This works fine whether I’m logged in or not.
When I try to open paginated pages like this:
domain.com/died-persons/2024/page/2/
it only works, when I’m logged in. When I’m logged out, the page isn’t found and I get a 404 error. (There is no cache plugin running while working on this problem)
In functions.php I have this:
function year_add_query_vars( $vars ) {
$vars[] = 'variable';
return $vars;
}
add_filter( 'query_vars', 'year_add_query_vars' );
add_rewrite_rule('died-persons/([0-9]{4})[/]page/([0-9]{1,})/?$', 'index.php?variable=$matches[1]&paged=$matches[2]', 'top');
In index.php I have this condition for getting the template:
if ( preg_match('#died-persons/([0-9]{4})/page/([0-9]{1,})/?$#', $_SERVER['REQUEST_URI'])) {
get_template_part( 'template-parts/content-personlist' );
}
In content-personlist.php I generate the list of items (persons), which I’m getting from an external WordPress database.
I think the really important point is that the existing code works as soon as you’re logged in. So what’s the difference between a logged-in and a non-logged-in user?
I would be happy if someone could help me with this problem. Thanks in advance!
Andreas
]]>I think I need to activate URL rewrite, but I am not sure what settings to use.
I have 4 different microsites on my site, what settings do I need if I want to have a post archive that links to single posts of a certain category?
In 2 of my microsites, the menu has items to external sites and one to the original domain.
Do I need Global rewriting? Or Selective rewriting? I don’t find what is the difference between the two.
Kind regards
]]>This installation is on a dev server so the primary url is dev.mysite.com and sub-sites are at sub1.dev.mysite.com, sub2.dev.mysite.com, etc. Similarly, I’ve created urls and DNS entries for assets such as mainassets.mysite.com, subsite1assets.mysite.com, etc… and configured Front Door to accept these. sub1.dev.mysite.com uses a child theme of the theme running on dev.mysite.com (this is possibly important?).
In W3TC’s network settings, I’ve disabled “Use single network configuration file for all sites” so that each site can have its own CDN settings as needed. In the main site’s settings, I’ve enabled the CDN on the general settings page and on the advanced page selected Generic Mirror and added the url to Front Door for it and this works perfectly.
However, in the sub-site, when I did the same procedure (using it’s unique asset url instead), I get the following problem – assets such as images for the site have their urls re-written correctly and are served correctly from the CDN. The theme file urls are behaving very strangely though. They’re being re-written as https://subsite1assets.mysite.com/https://dev.mysite.com/content/themes/{rest-of-path}
.
I’m still working on debugging this, but I’m curious if you know of any reason it would occur. It’s possible that I may just need to use a single configuration for all sites, but I’m hoping not to do that if possible.
Please let me know what additional information I can provide. Thanks for any insight you can offer!
]]>“?s=&ymm_search=1&orderby=name&post_type=product&_make”
]]>I’m working on url rewriting for which i used the below code;
function custom_add_rewrite_rule(){
$posts = get_posts( array( 'numberposts' => -1, 'post_type' => 'post') );
if( $posts ){
foreach($posts as $post ){
add_rewrite_rule(
$post->post_name . '/download/?$',
'index.php?name=' . $post->post_name . '&post_action=download&post_id=' . $post->ID,
'top'
);
}
}
}
add_action('init', 'custom_add_rewrite_rule');
above code working fine but the problem is that after working for hours it start giving 404 error and then i have to do Permallink save to make it work. I tried flushing rewrite rules on post update this isn’t a permanent solution.
Anyone can guide me how can i shout-out this permanently.
]]>function replace_text_wordpress($text) {
$text = str_replace('domain.com/wp-content/uploads/', 'domain.s3.amazonaws.com/uploads/', $text);
return $text;
}
add_filter('the_content', 'replace_text_wordpress');
]]>RewriteRule ^.$ /main-page/ [L] #custom line added
RewriteRule ^index\.php$ - [L] #default line. Custom code added above this.
What are the alternatives available in WordPress to achieve what I need?
Thank you.
]]>/users/steve/videos/2
…where “users” is the PHP page template that displays details on a user. So if we go to:
/users/steve/
…we see Steve’s home page. If we go to:
/users/steve/videos/
…we hit the page template for the video library, and we see Steve’s list of videos. And if we go to:
/users/steve/videos/2
…we hit a third page template, the video player page, where we see video id 2 displayed.
So we have three separate page templates, and we would like the child / parent relationship between them to be user page -> video library page -> video player page, for our breadcrumbs display.
The trick we can’t figure out is that “steve” and “2” are really params inserted into the url, interrupting the parent/child token relationship. And second, for the video player, there really isn’t a token there at all that maps to the video player page template. It’s just the presence of the “videos” token plus the additional numerical parameter that tells us this maps to the video player page template.
As alternative, we’ve figured out how to get /users/videos/steve/2 working. We’ve added this rewrite rule to our child theme’s functions.php file:
add_rewrite_rule(
'^users/videos/([^/]*)/([^/]*)/?',
'index.php?pagename=users/videos&users_filter_name=$matches[1]&user_video_id=$matches[2]',
'top');
(we’ve also defined the variables “users_filter_name” and “user_video_id” and we are successfully parsing them in the template)
But since what we really would like is /users/steve/videos/2 we tried updating the rule to:
add_rewrite_rule(
'^users/([^/]*)/videos/([^/]*)/?',
'index.php?pagename=users/videos&users_filter_name=$matches[1]&user_video_id=$matches[2]',
'top');
That didn’t seem to work (it just loaded the ‘/users/’ page) so we’re obviously doing it incorrectly. Is what we want achievable with this structure?
Thanks!
]]>