-1

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:

http://example.com/folder1/folder2/page.php

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

http://example.com/testing/folder2/page.php

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
</IfModule>

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

5
  • 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, 2014 at 11:05
  • Is this about rewriting or redirecting? Sep 25, 2014 at 11:21
  • rewriting @ialocin
    – papa.ramu
    Sep 25, 2014 at 11:27
  • Ok, the code you posted does perform a redirect.. What about this and/or this. Sep 25, 2014 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? Sep 25, 2014 at 13:45

2 Answers 2

0

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

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

-1

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
</IfModule>
1
  • Don't use the answers to make comments.
    – cybmeta
    Dec 22, 2014 at 16:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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