I am wondering wether it's possible to use Apaches .htaccess to rewrite a folder name - using a WordPress function.

Lets say I have a url like:


Now I want to rewrite the url to (for example)


The folder1 is an existing url. How can I change it to testing?

The following I found "somewhere in the internet":

<IfModule mod_alias.c>
    RedirectMatch 301 /testing/folder2/(.*) /folder1/folder2/$1

I need it as a PHP function to use it in WordPress.

  • 1
    Please read How to Ask, take a look at the editor and use the editor buttons when asking questions. Keep that in mind for further questions. Thanks. – kaiser Sep 25 '14 at 11:05
  • Is this about rewriting or redirecting? – Nicolai Sep 25 '14 at 11:21
  • rewriting @ialocin – papa.ramu Sep 25 '14 at 11:27
  • Ok, the code you posted does perform a redirect.. What about this and/or this. – Nicolai Sep 25 '14 at 11:41
  • I don't get what is the question about, is it htaccess question, or a php and how is it related to wordpress at all? – Mark Kaplun Sep 25 '14 at 13:45

You can do rewrites in wordpress by using the add_rewrite_rule() function.

Please see: https://codex.wordpress.org/Rewrite_API/add_rewrite_rule


Thanks, just what I needed after chaning the foldername (aka customer type name) I got too many 404. so I did:

<IfModule mod_alias.c>
    RedirectMatch 301 /old_custom_post_type/(.*) /new_custom_post_type/$1
  • Don't use the answers to make comments. – cybmeta Dec 22 '14 at 16:07

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.