Custom rewrite rule for backend/admin?

I would like to create a custom rewrite rule that will take the URL:

http://domain/submit-project/add

Read More

but display

http://domain/wp/wp-admin/post-new.php?post_type=project

Is there any way to do this? I am trying to add the rewrite rule so in my theme’s functions.php

add_action( 'init', 'add_custom_rules' );

function add_custom_rules() {
  add_rewrite_rule(
    "^submit-project/add",  
        "/wp/wp-admin/post-new.php?post_type=project",  
        "top");
}

I’ve tried flushing the rules, but this always seems to enter some kind of loop always going back to the ‘login’ page.

Edit

  1. The URL is actually just 404-ing now
  2. I should add that I do have a page with the slug submit-project and thus the URL: http://domain.com/submit-project in case it matters.
  3. I’ve installed the plugin Rewrite Rules Inspector and can’t seem to find my rule in there.

Related posts

1 comment

  1. In general, it is possible, but you need to define ADMIN_COOKIE_PATH in your wp-config.php to the value / which might cause security issues.

    First of all define this rewrite rules in your .htaccess right before the rewrite rule of wordpress:

    # Make sure, there is a trailing slash
    RewriteRule ^submit-project/add$ submit-project/add/ [R=301,L]
    # mask the urls
    RewriteRule ^submit-project/add/$ /wp/wp-admin/post-new.php [L,QSA]
    RewriteRule ^submit-project/add/post.php?$ /wp/wp-admin/post.php [L,QSA]
    # this is the wordpress rule:
    RewriteRule . /index.php [L]
    

    Now you need to define the constant in the wp-config.php

    define( 'ADMIN_COOKIE_PATH', '/' );
    

    I recommend not to use this on a productive site. Consider to offer a special input formular in the frontend using shortcodes or something less invasive than the shown example.

Comments are closed.