I Have Developed a plugin. And I created a rewrite rule manually in .htaccess file.

RewriteEngine On 
RewriteCond %{SCRIPT_FILENAME} !-d 
RewriteCond %{SCRIPT_FILENAME} !-f 
RewriteRule ^(\w+)$ ./index.php?id=$1

This rule is used to get the data after the index.php as id. It's working correctly. But I want to create this rewrite rule on my plugin activation. I searched a lot, But little confused. In my rule, http://www.url.com/index.php/example if this is the url I need to get example as id in $_GET.

How can i solve this situation?.

  • are you sure this rewrite rule doesn't interfere with other rewrite rules of WordPress ? – mmm Jul 24 '18 at 6:59
  • This is rewrite rule is working correctly, doesn't interfere with any of the wordpress pages or posts. I just want to create rewrite rule for custom url. – Midlaj Jul 24 '18 at 7:04
  • the url look like this. www.myblog.com/john so i need to get the john. – Midlaj Jul 24 '18 at 7:07

finally I completed, using this below hook


function output_htaccess( $rules ) {
$new_rules = <<<EOD
RewriteEngine On  
RewriteCond %{SCRIPT_FILENAME} !-d  
RewriteCond %{SCRIPT_FILENAME} !-f  
RewriteRule ^(\w+)$ ./index.php?id=$1

return  $new_rules . $rules;
add_filter('mod_rewrite_rules', 'output_htaccess');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.