Questions tagged [rewrite-rules]

Rewrite rules modify a web URL's appearance. This modification is called URL rewriting. Rewritten URLs (sometimes known as short, fancy URLs, search engine friendly - SEF URLs, or slugs) are used to provide shorter and more relevant-looking links to web pages. The technique adds a layer of abstraction between the files used to generate a web page and the URL that is presented to the outside world.

Filter by
Sorted by
Tagged with
0 votes
1 answer
780 views

WordPress add_query_arg from ajax and make url friendly

In WordPress I have set a query arg in ajax like this add_action( 'wp_ajax_get_prepare_link', 'prepare_link'); add_action( 'wp_ajax_nopriv_get_prepare_link', 'prepare_link'); function prepare_link()...
0 votes
2 answers
723 views

How to use endpoint, but remove/rewrite endpoint base?

I've been messing around with rewrites and query_var to generate some listings, for example: ~/my-page/?my_var=1 ~/my-page/?my_var=2 ~/my-page/?my_var=3 After perusing StackExchange and the ...
2 votes
1 answer
897 views

Rewrite Endpoints and CPTs - How to use in a plugin

I'm working on rewrite rules for a plugin that uses a URL endpoint, /modifier, to create a query_var &modifier=1 to signify it should do something else. The rewrite deals with URLs where /...
0 votes
0 answers
16 views

Taxonomy archives based on Custom Post Types

I have the custom post types, reception_units, year_1_units, year_2_units, year_3_units, year_4_units, year_5_units, year_6_units and resources. I want to create archives for the different post types ...
0 votes
0 answers
30 views

Custom post permalinks for specific categories

I have specific categories posts where i want to remove category name from URL. My current post link is: https://example.com/my_cat_name/post_name/ I want: https://example.com/post_name/ But only for ...
0 votes
0 answers
67 views

Is there a way to use rewrite rules in Wordpress to correctly render a page or post?

I made a Wordpress plugin that was able to rewrite URLs so that users could add a vanity segment at the end of the URL so that every page had personalized information via an external API call with the ...
0 votes
0 answers
18 views

how to properly format custom post type rewrite to get specific URL structure for archive and post views

The goal I created a custom post type for events listing and want to achieve the following URL structures all archives url This url returns 404 error https://example.com/events-list/ single archive ...
0 votes
0 answers
28 views

Preserve the url for subpage

I have a units page abc.com/units When I visit abc.com/units/toronto this shows a 404 page. I want to preserve the url /units/* and basically just redirect to units page while maintaining the url So,...
0 votes
0 answers
27 views

Redirect domain and subdomain to rewrited rule depending on $_SERVER['REMOTE_ADDR']

In first question : Must or do I have to use .htaccess rather than wp redirect ? I’m loolink for to use wp_redirect() to redirect website to new permalink structure for language. Is it the good ...
0 votes
1 answer
123 views

How to set product category base the same as shop base in WooCommerce?

I'm using WooCommerce on a WordPress. I would like my products and product categories to have the same url base. E.g. www.example.com/shop/product-category www.example.com/shop/sample-product Using ...
0 votes
0 answers
28 views

Rewrite rules are chosen inconsistently

I am trying to get some rewrite rules working with Polylang and I'm using the Rewrite Rules Inspector plugin to inspect the rules. Different rules are applying in different environment: my local ...
0 votes
0 answers
28 views

Nesting add_rewrite_rule() with custom page and subcategories

The url structure looking for is : blog/category/subcategory/ blog/category/post/ blog/category/subcategory/post/ My rewrite rules : add_rewrite_rule( 'blog/([^/]+)/([^/]+)/?$', 'index.php?...
0 votes
1 answer
45 views

openlitespeed rewrite rules conversion from apache

# BEGIN Wordpress <IfModule mod_rewrite.c> RewriteEngine on # behind proxy RewriteCond %{HTTP:X-FORWARDED-PROTO} ^http$ RewriteRule (.*) https://%{HTTP_HOST}/$1 [R=301,L] # plain RewriteCond %{...
0 votes
1 answer
837 views

How bad is flush_rules() on init hook?

According to the Codex: [...] This function can be extremely costly in terms of performance. It should be used as sparingly as possible - such as during activation or deactivation of plugins or ...
0 votes
2 answers
29 views

rewrite for subpage seems to loose parameter

I have defined a rewrite rule for a subpage 'vehiculo' (which is a template-page in my theme folder), and subpage of 'vehiculos', because I want a pretty URL and the code is handled in the template ...
0 votes
0 answers
14 views

WordPress Custom rewrite does not work with seo url

I try to generate 3 custom rewrite rule, it does not really work very well. Here is my plugin class file. <?php class QuestionAndAnswers { public $isUserLoggedIn; public function ...
0 votes
0 answers
22 views

How do I defeat the default action of a query variable on home page redirects to posts page

I am using a query variable to pass some information around the site. It works fine, except that Wordpress is operating some rewrite in the background. In particular, on the (static) home page adding ...
16 votes
8 answers
24k views

Where, When, & How to Properly Flush Rewrite Rules Within the Scope of a Plugin?

I am having a bit of a strange issue with rewrite rules not flushing properly. I have tried using flush_rewrite_rules(); and flush_rewrite_rules(true);. I have also tried globalizing $wp_rewrite ...
1 vote
2 answers
121 views

Two taxonomies with the same slug

There is a custom post type "real estate" with the slug "sale" and 2 taxonomies city and property type. It is necessary that taxes are displayed refer to the same slug, that is ...
8 votes
6 answers
8k views

Multiple post types - share same ReWrite slug?

I've run into another wonderful 404 issue. I'm trying to have 2 seperate post types that share the same rewrite slug. I've flushed my rewrite rules, and when I test only 1 of the CPT works- the ...
0 votes
2 answers
54 views

Wordpress picks a wrong template if ?cat= is used as URL parameter

I have a website with the following article structure. This works and uses archive.php template like it's supposed to website.com/category/articles/arrester/?tag=online-lectures This also works and ...
0 votes
1 answer
39 views

Search pagination rewrite to fix 404

I'm wondering if anyone can help me out here? Basically, I think I need to use add_rewrite_rule() to get pagination working in my search results, as I've gone beyond the default query due to a bunch ...
0 votes
0 answers
18 views

How to combine nearly identical custom rewrite rules for WordPress

I have 22 rewrite rules in my functions.php. I was wondering if it is possible to combine some of the nearly identical rewrite rules. Combining identical rewrite rules for different PAGES: '^videos/...
0 votes
1 answer
46 views

wordpress category rewrite rule with pagination

with the help of someone here I was able to filter two or more categories via this rewrite rule '^combine/([^/]*)/?([^/]*)/([^/]*)/?','index.php?category_name=$matches[1]+$matches[2]+$matches[3]', '...
1 vote
1 answer
44 views

Custom URL Rewrite Rules not working

I added the following custom routes to WordPress: function add_custom_rewrite_rules() { add_rewrite_rule( 'generate/?', 'index.php?custom_route=generate', 'top' ); add_rewrite_rule( 'random/?',...
0 votes
0 answers
12 views

make a new structure tag that does some processing

my goal is to have short urls. I'm trying to use base_convert so that "site.com/p=10000" becomes "site.com/7ps" My code is such a mess I don't even think it would be helpful to ...
0 votes
0 answers
57 views

WP-Include rewrite directory

I try few day to rewrite wp-include directory but not success. In .htaccess I add next line <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^main/(.+) /wp-includes/$1 [L,...
0 votes
0 answers
25 views

add_rewrite_rule doesn't work when trying to add a new parameter at the end of URL

I wish to add a userq parameter at the end of a URL with the username such as john. I wish to change, example.com/user/john to, example.com/user/index.php?userq=john I tried this and this and they ...
0 votes
1 answer
201 views

Dynamic WordPress rewrite rules for multiple custom post types

I'm very new to WordPress development and would like some pointers if this is possible. So I have this rewrite rule for my custom sidebar in functions.php: add_action('init', 'cpt_rewrite'); function ...
0 votes
0 answers
66 views

Direct domain alias to a specific WordPress page without the page in the URL

I have client with an existing website on domainA.com. They want to use another domain (domainB.com) for some marketing of a specific product that is detailed on a page of their existing website. So I ...
0 votes
1 answer
48 views

add_rewrite_rule image from /images/site2/favicon.ico to /favico.ico

Please Friend all, help me! How add_rewrite_rule in multisite subdomain from images via functions.php not .htaccess My Image Path https://cdn.domain.com/images/site2/favicon.ico But I want change url ...
1 vote
0 answers
173 views

Share same Slug for a Custom Post Type and 2 Taxonomies

I'm trying to achieve an URL structure that implies sharing the same slug ("videos") for a Custom Post Type (video), and two Taxonomies (video_category, video_tag), in order to have: Page: /...
0 votes
0 answers
26 views

rewriteRules WP6

I’ve got a custom post type slides which is set up this way function register_slides() { $labels_slides = array( 'name' => __( 'Slides', 'slides' ), 'singular_name' => __( '...
0 votes
0 answers
118 views

Standard Regex syntax doesn't work in WordPress rewrite rule

I've run into a regex issue while adding a rewrite rule into a Wordpress plugin. This blog has been helpful and the redirect works correctly after following this: https://brightminded.com/blog/...
0 votes
0 answers
50 views

Wordpress rewrite rule - not able to access second and third parameters

I have a rewrite rule; add_rewrite_rule( 'jobs/search/([^/]+)/state/([^/]+)/position/([^/]+)/?$', 'index.php?post_type=job&search=$matches[1]&state=$matches[2]&position=$matches[...
1 vote
2 answers
982 views

add_rewrite_rule not working with custom variables

I posted this in stackoverflow as well, so hope it's good to post here as well! I think this is my last problem to solve before everything clicks into place: I have a homepage with a custom plugin ...
1 vote
3 answers
6k views

Viewing category pages without the word 'category' in URL

When I view a static page its url is like: http://example.com/mybooks/ When I view a category page its url is like: http://example.com/category/books-ebooks/ For SEO, I want some modification so that ...
3 votes
1 answer
62 views

What is the best way to relate different custom post types?

Let's say I have 3 CPTs: series, seasons, and episodes. Now if I post in these custom post types the URL would be: Series CPT > post name: sample serie > URL: site.com/series/sample-serie ...
1 vote
1 answer
48 views

Standard Htaccess directives disappear by themselves

I have an odd issue on one of my websites. I'm talking about the standard, native, url directives put by wordpress, that just plain disappear from time to time, which of course breaks my site. Here is ...
0 votes
1 answer
907 views

'Unsupported Operand Types' error stemming from taxonomy re-writes with PHP 8.1

I was getting a FATAL ERROR in WordPress, but only on the front end. I KNOW the error is within my plugin, but the stack trace returns info about WP Core files, and doesn't identify where in my ...
0 votes
0 answers
27 views

Rewrite rule to simulate page hierarchy results in 404

On my WordPress site, I want pages with slugs beginning with outline- or result- to be accessible by requesting URI's that begin with outline/ or result/ instead, as if the pages in question were ...
1 vote
0 answers
38 views

Rewrite URLs in a Custom Post Type with Multiple Taxonomies

I'm trying to filter the content of a custom post type, but I can only get it to read the first variable. The custom post type has 3 associated taxonomies that if I pass them through GET in the URL it ...
-1 votes
1 answer
3k views

Rewrite Page Parameters

i have a page call "city" http://localhost/wordpress/city/ and it get details from mysql by url id like http://localhost/wordpress/city/?id=paris and i want to change it like http://localhost/...
-1 votes
2 answers
914 views

add_rewrite_rule() driving me crazy, rewrite not working when analyzer says it should

I have a special situation and need some help achieving the final step. Background: When I access mydomain.com/category/postname, I get the post as expected. When I access mydomain.com/category/...
0 votes
1 answer
125 views

Custom archive URL as a subfolder of the custom post type slug

I have a Custom Post Type called Whatever. The slug for this CPT is whatever. By default, I can access the posts archive in the frontend at /whatever and each post at /whatever/post-slug But I would ...
0 votes
1 answer
512 views

issue with wordpress [wp-admin] redirects, when using kubernetes ingress hosting two wordpress websites using path

i'm trying to setup a kubernetes deployment for two wordpress websites in different pods, each will have it's own deployment and service, etc..., under the same ingress, i have setup the ingress this ...
-1 votes
1 answer
690 views

Wordpress Pagination Custom Rewrite Rule for Pages

Hi I am trying to run a pagination rule for the following for some custom pages that are getting data from an external api the current structure is like and it working fine http://domain.com/?...
-1 votes
1 answer
93 views

Configuring static page with add_rewrite_rule gives 404 after navigating to Permalinks admin panel

I would like to create a simple static page in my theme which would then show some practical information on a certain event. The page would be served on the path /practical. For now, there are no ...
0 votes
1 answer
159 views

Programmatically add a custom url route "/category/index.json" to return a collection of posts in json

I would like to serve a list of posts pertaining to a specific category in JSON format at this endpoint: /category/category-slug/index.json I figured I could, as a start, point to the REST API for the ...
0 votes
0 answers
20 views

CPT Archive Pagination - Page not found

I have the following code to register my CPT, related taxonomy and rewrite rules. $store_name = 'store' add_action('init', function () use ($store_name) { register_post_type( 'my_sample_cpt', ...

1
2
3 4 5
24