1
votes

I have a Wordpress blog installed in a subfolder and I would like to replace a part of the url of the post.

Right now it is like this: http://domain.com/wordpress/{permalink-structure}

What I would like to achieve (without moving the site) is: http://domain.com/{permalink-structure}

I tried changing the site url (and followed the instructions provided by WP on how to do this), but if I do this, my front-end stops working ( I am not retrieving the posts etc through the WP-API and I work with AngularJS)

Is there an easy way to automatically modify the (by wordpress generated) url of all future posts by using a plugin or modifying the source code? Or via .htaccess?

Redirecting via htaccess is my preferred option but when I tried this, the wp-api plugin (accessible via domain.com/wordpress/wp-json/* stopped working

Just to be clear: I am not accessing the posts by the generated URLS, I retrieve them via the API and the only thing I want is that the link object in the retrieved post has a different URL.

3
1) Make sure you've changed your htaccess Rewrite Base. 2) Are you using the "db search replace" tool that they suggest? Some of the permalinks are being stored in serialized strings, so you need more than simple phpmyadmin search & replace. - Ofir Baruch
I've updated my question so that it is more clear (I hope). This would only be for new posts, the old posts are not important. - rmuller
I've done it with PHP before, but it's more stable and a much better practice to just move the site. Down the line you may want to update wordpress or use various plugins, causes more maintenance. Just move it. - fred randall
@rmuller not posting as an answer yet because I'm not entirely sure if this works: did u add a rewrite rule for the wp-json/*? something like RewriteRule ^([_0-9a-zA-Z-]+/)?wp-json$ $1wp-json/ [R=301,L] in codex.wordpress.org/htaccess should allow you to do what you want and keeping required links redirect properly. - matrixanomaly
I will check this in a moment and report back. Thanks already - rmuller

3 Answers

2
votes

I don't know. Just try to help. This is my solution redirect what need to redirect.

    Options +FollowSymLinks
    RewriteEngine On
    RewriteRule ^wordpress/wp-json/(.*)$ http://domain.com/wordpress/wp-json/$1 [R=301,NC,L]
    RewriteRule ^wordpress/(.*)$ /$1 [R=301,NC,L]
0
votes

you want to change wordpress domain or URL. you need to perform following steps.

1 you need to modify all url's stored in database. I prefer to use https://interconnectit.com/ tool. It is pretty good and easy.

2 Once you update all database urls then you need to login in wp-admin and just update permalink settings.

  1. you need to check plugins too. Some plugins may get deactivated you need to activate them again.

Hope this will help.

-1
votes

check word press codex:

https://codex.wordpress.org/Giving_WordPress_Its_Own_Directory

you can display your word press without move your directory from sub folder to root folder and can remove sub-directory from URL.