How to redirect root folder as subfolder to site?
I am trying to implement the Wordpress REST API with React. Modern convention seems to be to set an API as a subfolder to a domain, i.e.
https://sitename.com/api/v1
I want to be able to go to
https://sitename.com/api/v1/wp-admin
And be able to sign into wordpress and have it so the REST api is accessed like:
https://sitename.com/api/v1/wp-json/wp/v2/pages
I have this file structure:
Inside api/
is the wordpress install. If I include the api inside the public folder and point towards the build folder with the virtual host, it works as desired, except for the fact that when I build the React app it clears the Wordpress install and restarts that whole process.
I tried setting the virtual host to the subfolder, but it is still returning a 404.
Edit: To get a simple instance of this running:
yarn create-react-app dir_name
cd dir_name
mkdir api
cd api
wp core download
# Add virtual host
# Generate SSL Cert
wordpress reactjs rest api virtualhost
add a comment |
I am trying to implement the Wordpress REST API with React. Modern convention seems to be to set an API as a subfolder to a domain, i.e.
https://sitename.com/api/v1
I want to be able to go to
https://sitename.com/api/v1/wp-admin
And be able to sign into wordpress and have it so the REST api is accessed like:
https://sitename.com/api/v1/wp-json/wp/v2/pages
I have this file structure:
Inside api/
is the wordpress install. If I include the api inside the public folder and point towards the build folder with the virtual host, it works as desired, except for the fact that when I build the React app it clears the Wordpress install and restarts that whole process.
I tried setting the virtual host to the subfolder, but it is still returning a 404.
Edit: To get a simple instance of this running:
yarn create-react-app dir_name
cd dir_name
mkdir api
cd api
wp core download
# Add virtual host
# Generate SSL Cert
wordpress reactjs rest api virtualhost
add a comment |
I am trying to implement the Wordpress REST API with React. Modern convention seems to be to set an API as a subfolder to a domain, i.e.
https://sitename.com/api/v1
I want to be able to go to
https://sitename.com/api/v1/wp-admin
And be able to sign into wordpress and have it so the REST api is accessed like:
https://sitename.com/api/v1/wp-json/wp/v2/pages
I have this file structure:
Inside api/
is the wordpress install. If I include the api inside the public folder and point towards the build folder with the virtual host, it works as desired, except for the fact that when I build the React app it clears the Wordpress install and restarts that whole process.
I tried setting the virtual host to the subfolder, but it is still returning a 404.
Edit: To get a simple instance of this running:
yarn create-react-app dir_name
cd dir_name
mkdir api
cd api
wp core download
# Add virtual host
# Generate SSL Cert
wordpress reactjs rest api virtualhost
I am trying to implement the Wordpress REST API with React. Modern convention seems to be to set an API as a subfolder to a domain, i.e.
https://sitename.com/api/v1
I want to be able to go to
https://sitename.com/api/v1/wp-admin
And be able to sign into wordpress and have it so the REST api is accessed like:
https://sitename.com/api/v1/wp-json/wp/v2/pages
I have this file structure:
Inside api/
is the wordpress install. If I include the api inside the public folder and point towards the build folder with the virtual host, it works as desired, except for the fact that when I build the React app it clears the Wordpress install and restarts that whole process.
I tried setting the virtual host to the subfolder, but it is still returning a 404.
Edit: To get a simple instance of this running:
yarn create-react-app dir_name
cd dir_name
mkdir api
cd api
wp core download
# Add virtual host
# Generate SSL Cert
wordpress reactjs rest api virtualhost
wordpress reactjs rest api virtualhost
asked Dec 24 '18 at 14:31
Daniel Foust
1241213
1241213
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
I believe if you install WordPress in the /api subfolder, that is considered root for the WP instance so no prefix will be added to the REST API endpoint.
To achieve that, you should use the "rest_url_prefix" filter. Something like:
add_filter( 'rest_url_prefix', 'change_api_slug');
function change_api_slug( $slug ) {
return 'api';
}
Here is a pretty good article: https://buddydev.com/modifying-api-base-url-prefix-for-wp-rest-api-plugin/
Hope it helps :)
That doesn't really address my question. My virtual host is returning 404 for the wordpress install inside the api/ folder. I feel this is because the React App is already using the domain and so there is a conflict with the domain. I've solved it currently by adding a symbolic link to the build folder, but i feel that isn't the correct way to solve it.
– Daniel Foust
Dec 26 '18 at 0:50
add a comment |
The best I've came up with is attaching a symbolic link to the api/
directory and linking it to the build/
directory.
# Source->Destination
ln -s /var/www/site.com/public/api /var/www/site.com/build/
Depending on your configuration you may have to change api/
group once you do a yarn build
for the server to have access for Wordpress (to add plugins for example).
Quick run through:
ln -s /var/www/site.com/api /var/www/site.com/public/
yarn build/
sudo chown -R :www-data build/
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53914705%2fhow-to-redirect-root-folder-as-subfolder-to-site%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I believe if you install WordPress in the /api subfolder, that is considered root for the WP instance so no prefix will be added to the REST API endpoint.
To achieve that, you should use the "rest_url_prefix" filter. Something like:
add_filter( 'rest_url_prefix', 'change_api_slug');
function change_api_slug( $slug ) {
return 'api';
}
Here is a pretty good article: https://buddydev.com/modifying-api-base-url-prefix-for-wp-rest-api-plugin/
Hope it helps :)
That doesn't really address my question. My virtual host is returning 404 for the wordpress install inside the api/ folder. I feel this is because the React App is already using the domain and so there is a conflict with the domain. I've solved it currently by adding a symbolic link to the build folder, but i feel that isn't the correct way to solve it.
– Daniel Foust
Dec 26 '18 at 0:50
add a comment |
I believe if you install WordPress in the /api subfolder, that is considered root for the WP instance so no prefix will be added to the REST API endpoint.
To achieve that, you should use the "rest_url_prefix" filter. Something like:
add_filter( 'rest_url_prefix', 'change_api_slug');
function change_api_slug( $slug ) {
return 'api';
}
Here is a pretty good article: https://buddydev.com/modifying-api-base-url-prefix-for-wp-rest-api-plugin/
Hope it helps :)
That doesn't really address my question. My virtual host is returning 404 for the wordpress install inside the api/ folder. I feel this is because the React App is already using the domain and so there is a conflict with the domain. I've solved it currently by adding a symbolic link to the build folder, but i feel that isn't the correct way to solve it.
– Daniel Foust
Dec 26 '18 at 0:50
add a comment |
I believe if you install WordPress in the /api subfolder, that is considered root for the WP instance so no prefix will be added to the REST API endpoint.
To achieve that, you should use the "rest_url_prefix" filter. Something like:
add_filter( 'rest_url_prefix', 'change_api_slug');
function change_api_slug( $slug ) {
return 'api';
}
Here is a pretty good article: https://buddydev.com/modifying-api-base-url-prefix-for-wp-rest-api-plugin/
Hope it helps :)
I believe if you install WordPress in the /api subfolder, that is considered root for the WP instance so no prefix will be added to the REST API endpoint.
To achieve that, you should use the "rest_url_prefix" filter. Something like:
add_filter( 'rest_url_prefix', 'change_api_slug');
function change_api_slug( $slug ) {
return 'api';
}
Here is a pretty good article: https://buddydev.com/modifying-api-base-url-prefix-for-wp-rest-api-plugin/
Hope it helps :)
answered Dec 24 '18 at 17:51
FrancescoCarlucci
726610
726610
That doesn't really address my question. My virtual host is returning 404 for the wordpress install inside the api/ folder. I feel this is because the React App is already using the domain and so there is a conflict with the domain. I've solved it currently by adding a symbolic link to the build folder, but i feel that isn't the correct way to solve it.
– Daniel Foust
Dec 26 '18 at 0:50
add a comment |
That doesn't really address my question. My virtual host is returning 404 for the wordpress install inside the api/ folder. I feel this is because the React App is already using the domain and so there is a conflict with the domain. I've solved it currently by adding a symbolic link to the build folder, but i feel that isn't the correct way to solve it.
– Daniel Foust
Dec 26 '18 at 0:50
That doesn't really address my question. My virtual host is returning 404 for the wordpress install inside the api/ folder. I feel this is because the React App is already using the domain and so there is a conflict with the domain. I've solved it currently by adding a symbolic link to the build folder, but i feel that isn't the correct way to solve it.
– Daniel Foust
Dec 26 '18 at 0:50
That doesn't really address my question. My virtual host is returning 404 for the wordpress install inside the api/ folder. I feel this is because the React App is already using the domain and so there is a conflict with the domain. I've solved it currently by adding a symbolic link to the build folder, but i feel that isn't the correct way to solve it.
– Daniel Foust
Dec 26 '18 at 0:50
add a comment |
The best I've came up with is attaching a symbolic link to the api/
directory and linking it to the build/
directory.
# Source->Destination
ln -s /var/www/site.com/public/api /var/www/site.com/build/
Depending on your configuration you may have to change api/
group once you do a yarn build
for the server to have access for Wordpress (to add plugins for example).
Quick run through:
ln -s /var/www/site.com/api /var/www/site.com/public/
yarn build/
sudo chown -R :www-data build/
add a comment |
The best I've came up with is attaching a symbolic link to the api/
directory and linking it to the build/
directory.
# Source->Destination
ln -s /var/www/site.com/public/api /var/www/site.com/build/
Depending on your configuration you may have to change api/
group once you do a yarn build
for the server to have access for Wordpress (to add plugins for example).
Quick run through:
ln -s /var/www/site.com/api /var/www/site.com/public/
yarn build/
sudo chown -R :www-data build/
add a comment |
The best I've came up with is attaching a symbolic link to the api/
directory and linking it to the build/
directory.
# Source->Destination
ln -s /var/www/site.com/public/api /var/www/site.com/build/
Depending on your configuration you may have to change api/
group once you do a yarn build
for the server to have access for Wordpress (to add plugins for example).
Quick run through:
ln -s /var/www/site.com/api /var/www/site.com/public/
yarn build/
sudo chown -R :www-data build/
The best I've came up with is attaching a symbolic link to the api/
directory and linking it to the build/
directory.
# Source->Destination
ln -s /var/www/site.com/public/api /var/www/site.com/build/
Depending on your configuration you may have to change api/
group once you do a yarn build
for the server to have access for Wordpress (to add plugins for example).
Quick run through:
ln -s /var/www/site.com/api /var/www/site.com/public/
yarn build/
sudo chown -R :www-data build/
edited Dec 27 '18 at 18:13
answered Dec 27 '18 at 17:57
Daniel Foust
1241213
1241213
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53914705%2fhow-to-redirect-root-folder-as-subfolder-to-site%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown