Redirect root to subdirectory apache - wordpress

I have an apache server with a WordPress website set up at root and a WordPress website in a subdirectory. I would like for the website in the subdirectory to be the default website. For example, when someone goes to www.example.com I would like for them to see the website that is actually located at www.example.com/newsite but the URL needs to stay the same, www.example.com.
Is doing something like that possible with say a 301 redirect or some other method?

check this out, you just need some htaccess changes:
https://codex.wordpress.org/Giving_WordPress_Its_Own_Directory

You can simply move/copy the files to the root folder in case you are having root access.
cp -pR /path/to/rootfolder/subdirectory(wordpress)/* /path/to/rootfolder/
Thats it. Don't complicate by putting redirects.
In case you are having a control panel like cPanel, Its easy to put redirects. But as far as I concern moving/copying the files are more reliable.

Related

Moved Wordpress to a subdirectory, don't want site-url to redirect to my subdirectory

I've searched a while but couldn't find an answer to this question yet. I had WP originally installed in the site root and moved it to a subfolder and went through the common steps necessary. I do this because I want to run wordpress only for blogging reasons and keep another HTML site as my main project that I want to access through my domain www.example.com and the wordpress blog through www.example.com/blog/
I moved the WP system therefore to /blog and changed the site address and wp address to that folder and followed the usual steps. Everything works just fine. Still when I enter my domain it redirects automatically to the /blog subdirectory and not to the site that lies in the root that has a index.html. There is no .htaccess file in the root or anything similar. How is that possible? Happy about all suggestions.

Rewrite wordpress url to subdomain

i have a wordpress site let just call it testing.com
with a page url called blog/ which can access via testing.com/blog
i am using NGINX as the web server.
How do i rewrite the testing.com/blog to blog.testing.com with all its content still intact?
//edit
in this case, /blog is a page in the wordpress and not the wordpress itself, only that page and all the link inside the page would be rewrite to the subdomain and nothing else
example:
inside of the blog.testing.com there was 2 more link such as:
1. older post
(original link will be testing.com/blog/page/2 and change it to blog.testing.com/page/2)
1. read more on each post
(original link will be testing.com/2017/05/testpost1 and change it to blog.testing.com/2017/05/testpost1)
//end of edit
so as to say as if i am opening testing.com/blog in blog.testing.com
i have tried rewrite and proxy pass
location ^~ /blog/ {
rewrite ^/admin(.*) http://blog.testing.com$uri permanent;
}
with the above block
the result is same as return the url only and not with the supposed content.
or is it not possible to do so?
Hi assuming that you don't want to keep the URL testing.com/blog at all and instead want to use the subdomain blog.testing.com then effectively what you want to achieve is a WordPress migration. There are a number of ways you can achieve a migration, depending on how technically able you are. The easiest way is probably to install and use a WordPress migration plug in such as WordPress Duplicator or WordPress Move. Please take a backup of your files AND database before you start.
The official WordPress guide to migration can be found at https://codex.wordpress.org/Moving_WordPress
In short you would create the subdomain, then move (migrate) the site that's currently at testing.com/blog to the subdomain blog.testing.com
If the subdomain directory is to be left at /blog and you are just pointing the subdomain to that directory, then you might be able to do what you need to do just by updating the database to reset all the internal URLs in the WordPress database. In this case you could consider using https://interconnectit.com/products/search-and-replace-for-wordpress-databases/
This is what I tend to use when migrating sites from test to live. Hope this helps.

Redirect home page to subdirectory with nginx

I want to have the WordPress installation in /wordpress in my root directory, but all the actual links be in the form of domain.com/blog/something/ (site address).
By following a tutorial, I managed to put WordPress in its own directory, and change the site's address to domain.com/blog instead of just domain.com. All of the links work fine, except that I can still visit domain.com and see my page.
I would like to have domain.com redirect to domain.com/blog, in the most WordPress-friendly/aware way possible.
The tutorial above does provide information on how to accomplish that, but only for Apache. And I'm using Nginx.
I don't know your nginx config, but the easiest way ever would be
location / {
return 301 http://example.com/wordpress
}

Sub domain redirect (htaccess)

There is soooo much information about htaccess redirect that I think I'm lost.
Here is my current structure
/web/
/web/CMS/
In the root I have a vBulletin forum and in /CMS/ I have wordpress. (Ideally I should have vBulletin in a /FORUM/ folder maybe?)
I'd like to setup something like this:
www.domain.com OR domain.com goes to /web/CMS/
forum.domain.com OR forums.domain.com goes to /web/
Then any other subdomain goes to /web/CMS/ (as I'll be using the multi site network of Wordpress)
I have 2 questions:
What would be the best structure for this? Maybe I should have my CMS as root and my forum in a folder?
How can I do an htaccess that does the job? (do I also need one in /web/CMS/?)
Thank you so much in advance.
If you have vBulletin in your root and you want it to go to forums, you should consider moving it into it's own directory called /forums. Inside the /forums directory, you'll have a .htaccess file generated by vBulletin.
You can keep your WordPress inside /CMS. WordPress will and should have its own htaccess file.
Now if you want to set a subdomain, you'll have to look into your DNS settings and at a minimum setup an A record. If you're on cPanel, this is pretty simple to do inside your DNS Zone section.

Any way of mapping the wordpress installation to the website root?

I installed Wordpress on a cPanel account, and it's accessible by visiting website.com/wordpress. What would I need to do to make it so that when a user visits website.com , he actually sees the website.com/wordpress ? I think there is a better solution than adding a redirect inside an index.html.
You can use .htaccess to make the wordpress location as your Directory index using a .htaccess file in your root above wordpress folder..
and include following in that .htaccess file
DirectoryIndex wordpress/index
Though I do not know about the cPanel admin section - look into your domain configuration or general settings: There should be a place where you can set the the target of the domain or your 'home directory'. it currently should point to the root directory '/'.
Simply let it point to the '/wordpress' folder and you should be fine. If you do not have access to the domain config, install the wordpress directly into the root directory.

Resources