I have a problem with the Rewrite Url Wordpress, I added this code in functions.php on my child theme, and I have already 404 error.
function custom_rewrite_basic() {
add_rewrite_rule('^leaf/([0-9]+)/?', 'index.php?p=$matches[1]', 'top');
}
add_action('init', 'custom_rewrite_basic');
Whatever the rule, it does not work
An idea?
thank you
Related
I need a rewrite rule to catch any URL on my WordPress except my existing pages and posts.
The following code in functions.php rewrites all URLs. How to make this exclude existing WordPress pages/posts?
function custom_rewrite_rule() {
add_rewrite_rule('^.([^/]*)?', 'index.php?page_id=5', 'top' );
}
add_action('init', 'custom_rewrite_rule', 10, 0);
Thanks.
I need the URL's to look like this:
http://localhost/TestProjects/wordpress/gmat/resources etc.
I wrote the below function in my functions.php file of my theme folder
add_action('init', 'custom_rewrite_basic');
function custom_rewrite_basic() {
$rcat='(gmat|gre|sat|cat)';
add_rewrite_tag( '%rootcat%',$rcat);
add_rewrite_rule('^{$rcat}/resources/', 'index.php? pagename=leap_resources&rootcat=$matches[1]', 'top');
}
I am working on a wordpress site that is running in a subdomain.
I have added the subfolder on WP .htaccess file to let all the site and permalinks work, so my WP site is running under
http://example.com/subfolder/
Now I need to do the following:
I have this permalink structure that goes to a post:
example.com/subfolder/the-post-permalink
And I need to add a rule that send this URL:
example.com/subfolder/the-post-permalink-category
to:
example.com/subfolder/the-post-permalink?param=category
So the post page displayed will be the same, but I will get a GET parameter with "param" value that was sent in the rewrite rule.
I have tried this with the add_rewrite_rule() method on the functions.php file, but could not make it work. Tried adding or not the subdolfer in the rule.
add_action('init', 'add_htaccess_redirects' ,10, 0);
function add_htaccess_redirects()
{
add_rewrite_rule(
'^subfolder/the-post-permalink-(.*)',
'subfolder/the-post-permalink?param=$matches[1]',
'top'
);
}
and
add_action('init', 'add_htaccess_redirects' ,10, 0);
function add_htaccess_redirects()
{
add_rewrite_rule(
'^the-post-permalink-(.*)',
'the-post-permalink?param=$matches[1]',
'top'
);
}
Any help please?
Thanks.
I am trying to create a custom page in Wordpress with a special URL Rewrite and I am trying the following:
function custom_rewrite_rule() {
add_rewrite_rule('^services/service-in-([^/]*)/?','index.php?page_id=238&location=$matches[1]','top');
}
add_action('init', 'custom_rewrite_rule');
However, when I go to domain.com/services/service-in-london/ I just get a 404 message.
I have also tried this manually in htaccess but just get a 404.
Can you please try below code
function custom_rewrite_rule() {
add_rewrite_tag('%location%', '([^/]*)');
add_rewrite_rule('^services/([^/]*)/?$', 'index.php?page_id=238&location=$matches[1]', 'top');
flush_rewrite_rules();
}
add_action('init', 'custom_rewrite_rule');
This quetsion has been ask al lot, but however I tried I get always a 404 page in WP
I have a templatepage (wp-content/themes/responsivewizzard.php cals: wizzard. ->
I Added a page in the admin sector. The name of the page = "tespage". The template I choose is "wizzard"
When in try example.com/wp/testpage -> I get my wizzard page. No worries.. but..
I like to add a subpage to my wizzardpage. For example:
example.com/wp/testpage/nice
When i try this I get a 404 page from WP
I added this code to my function.php file. This file is in wp-content/themes/responsive directory -> my default theme
function members_rewrite_rules()
{
add_rewrite_rule('testpage /(.+)/?$', 'index.php?pagename=testpage &subpage=$matches[1]', 'top');
}
add_action( 'init', 'members_rewrite_rules' );
function members_query_vars($query_vars)
{
$query_vars[] = 'subpage';
return $query_vars;
}
add_filter('query_vars', 'members_query_vars');
Please help me
I found out the soulution. You need to reset the permalinks in the setting menu..