Skip to main content
removed answer in question as an answer with the same information was created.
Source Link

I want to add a custom rewrite rule to my .htaccess.htaccess file using a function inside functions.php

The rewrite rule I want to add is as follows:

RedirectMatch 301 ^/author/(.+)$ http://name-blog.com/$1

I know there is a wordpressWordPress function that adds a rewrite rule to the .htaccess.htaccess:

$wp_rewrite->add_external_rule( 'mobile/([^/]+)$', 'mobile/index.php?action=$1' );

So, how can I use that to add my rewrite rule to .htaccess.htaccess?

SOLVED!

I found the solution just after posting here. Here is the codex: http://codex.wordpress.org/User:Amereservant/Editing_and_Customizing_htaccess_Indirectly

And this is the code I was looking for:

function my_htaccess_contents( $rules )
{
$my_content = <<<EOD
\n # BEGIN My Added Content
# Protect wpconfig.php
<Files wp-config.php>
    Order Allow,Deny
    Deny from all
</Files>
# END My Added Content\n
EOD;
    return $my_content . $rules;
}
add_filter('mod_rewrite_rules', 'my_htaccess_contents');

I want to add a custom rewrite rule to my .htaccess file using a function inside functions.php

The rewrite rule I want to add is as follows:

RedirectMatch 301 ^/author/(.+)$ http://name-blog.com/$1

I know there is a wordpress function that adds a rewrite rule to the .htaccess:

$wp_rewrite->add_external_rule( 'mobile/([^/]+)$', 'mobile/index.php?action=$1' );

So, how can I use that to add my rewrite rule to .htaccess?

SOLVED!

I found the solution just after posting here. Here is the codex: http://codex.wordpress.org/User:Amereservant/Editing_and_Customizing_htaccess_Indirectly

And this is the code I was looking for:

function my_htaccess_contents( $rules )
{
$my_content = <<<EOD
\n # BEGIN My Added Content
# Protect wpconfig.php
<Files wp-config.php>
    Order Allow,Deny
    Deny from all
</Files>
# END My Added Content\n
EOD;
    return $my_content . $rules;
}
add_filter('mod_rewrite_rules', 'my_htaccess_contents');

I want to add a custom rewrite rule to my .htaccess file using a function inside functions.php

The rewrite rule I want to add is as follows:

RedirectMatch 301 ^/author/(.+)$ http://name-blog.com/$1

I know there is a WordPress function that adds a rewrite rule to the .htaccess:

$wp_rewrite->add_external_rule( 'mobile/([^/]+)$', 'mobile/index.php?action=$1' );

So, how can I use that to add my rewrite rule to .htaccess?

Tweeted twitter.com/#!/StackWordPress/status/463639307891142656
added 598 characters in body
Source Link
Gixty
  • 1.1k
  • 2
  • 19
  • 37

I want to add a custom rewrite rule to my .htaccess file using a function inside functions.php

The rewrite rule I want to add is as follows:

RedirectMatch 301 ^/author/(.+)$ http://name-blog.com/$1

I know there is a wordpress function that adds a rewrite rule to the .htaccess:

$wp_rewrite->add_external_rule( 'mobile/([^/]+)$', 'mobile/index.php?action=$1' );

So, how can I use that to add my rewrite rule to .htaccess?

SOLVED!

I found the solution just after posting here. Here is the codex: http://codex.wordpress.org/User:Amereservant/Editing_and_Customizing_htaccess_Indirectly

And this is the code I was looking for:

function my_htaccess_contents( $rules )
{
$my_content = <<<EOD
\n # BEGIN My Added Content
# Protect wpconfig.php
<Files wp-config.php>
    Order Allow,Deny
    Deny from all
</Files>
# END My Added Content\n
EOD;
    return $my_content . $rules;
}
add_filter('mod_rewrite_rules', 'my_htaccess_contents');

I want to add a custom rewrite rule to my .htaccess file using a function inside functions.php

The rewrite rule I want to add is as follows:

RedirectMatch 301 ^/author/(.+)$ http://name-blog.com/$1

I know there is a wordpress function that adds a rewrite rule to the .htaccess:

$wp_rewrite->add_external_rule( 'mobile/([^/]+)$', 'mobile/index.php?action=$1' );

So, how can I use that to add my rewrite rule to .htaccess?

I want to add a custom rewrite rule to my .htaccess file using a function inside functions.php

The rewrite rule I want to add is as follows:

RedirectMatch 301 ^/author/(.+)$ http://name-blog.com/$1

I know there is a wordpress function that adds a rewrite rule to the .htaccess:

$wp_rewrite->add_external_rule( 'mobile/([^/]+)$', 'mobile/index.php?action=$1' );

So, how can I use that to add my rewrite rule to .htaccess?

SOLVED!

I found the solution just after posting here. Here is the codex: http://codex.wordpress.org/User:Amereservant/Editing_and_Customizing_htaccess_Indirectly

And this is the code I was looking for:

function my_htaccess_contents( $rules )
{
$my_content = <<<EOD
\n # BEGIN My Added Content
# Protect wpconfig.php
<Files wp-config.php>
    Order Allow,Deny
    Deny from all
</Files>
# END My Added Content\n
EOD;
    return $my_content . $rules;
}
add_filter('mod_rewrite_rules', 'my_htaccess_contents');
Source Link
Gixty
  • 1.1k
  • 2
  • 19
  • 37

How to add custom rewrite rule to .htaccess?

I want to add a custom rewrite rule to my .htaccess file using a function inside functions.php

The rewrite rule I want to add is as follows:

RedirectMatch 301 ^/author/(.+)$ http://name-blog.com/$1

I know there is a wordpress function that adds a rewrite rule to the .htaccess:

$wp_rewrite->add_external_rule( 'mobile/([^/]+)$', 'mobile/index.php?action=$1' );

So, how can I use that to add my rewrite rule to .htaccess?