Your regexp is too generic and doesn’t capture anything that will be placed in $matches. It seems you have little regexp experience, which is OK, it’s not that easy to learn about. Its syntax is exacting and often non-intuitive. I recommend you use a site like regexr.com to help you come up with workable regexp. You can place an example URL in the sample text, then fiddle with the regexp until it captures the data you need in $matches. It has a minimal reference feature to remind you about what regexp symbols do what.
Your regexp needs to match a static element like “jobdetails”, and capture the subsequent two elements into $matches. We use () to capture portions of the matched string.
Review this docs page for more information:
https://developer.ww.wp.xz.cn/reference/functions/add_rewrite_rule/
The user notes and examples should be helpful to you.
Don’t forget to visit the permalinks settings screen anytime you alter rewrite rules.
Hi bcworkz,
thank you for your answer, yes my regexp is very low, but the regexp in my case are worke fine: https://regexr.com/5lrlv
My problem is: Wordpres thinks i want surf to a other Site… i got the error 404…
How can i say to my wordpress installation i want a Site domain.com/example and ignores the rest of the URL… also domain.com/example/BLAH/BLUB <— wordpress looks 4 a Site example -> BLAH -> BLUB….
i hope you understand me….
Your regexp works too well. It traps normal post and page requests which are meant for other rules. It needs to be more discriminating, only matching requests that contain “jobdetails”. It also does not capture anything for use in $matches and similar place holders.
Also, if you don’t rewrite to index.php, from the docs page:
The $redirect argument works slightly differently when redirecting to a custom PHP script because WordPress delegates these redirects to .htaccess instead of processing them itself. For this reason, querystring variables should be written like $1 instead of $matches[1]. Given we’re redirecting to a custom PHP script, adding the same rewrite rule from our previous example would look like this:
function custom_rewrite_rule() {
add_rewrite_rule('^nutrition/([^/]*)/([^/]*)/?','url/to/my/script.php?food=$1&variety=$2','top');
}
add_action('init', 'custom_rewrite_rule', 10, 0);
Also note that the string being tested is not a full URL, the domain portion is stripped. You’re really matching something like “jobdetails/DKS4L676/”
now i have solved my problem.
thank you for your patience!
The problem was that the forwarding must of course be directed to the index.php with the name of the static page.
function custom_rewrite_rule() {
#add_rewrite_rule('^nutrition/([^/]*)/([^/]*)/?','url/to/my/script.php?food=$1&variety=$2','top');
add_rewrite_rule( '^stellenanzeige\/([^/]*)\/([^/]*)\/?', 'index.php?pagename=stellenanzeige&jobid=$matches[2]', 'top' );
}
add_action('init', 'custom_rewrite_rule', 10, 0);
add_filter( 'query_vars', function( $query_vars ) {
$query_vars[] = 'jobid';
return $query_vars;
} );