Moving WordPress from subdirectory to new domain - wordpress

I have a WordPress site stored and served from in a subdirectory: eg https://example.com/en/
We now need to serve it from the root of a new domain eg https://exampletwo.com/, ideally without moving the installation. The domain is already setup as a parked domain on the cpanel and serves the WordPress site correctly.
Changing the siteurl and homeurl automatically redirects https://example.com/en/ to the new location https://exampletwo.com to the correct location and works fine as expected.
The problem is with external links:
https://example.com/en/ now returns a WordPress 404 error. Setting up a page called /en/ putting a redirect to https://exampletwo.com/ works fine. A bit clumsy but works for now.
However they also used to have pages like
https://example.com/en/contact and these return server 404 errors outside of WordPress, i.e.:
The requested URL /index.php was not found on this server.
I'm trying to avoid physically moving the WordPress installation. I'm guessing that when making a request to the /en/ directory, it's actually looking for resources in the /en/en/ directory.
Is it possible to accomplish this using .htaccess / WordPress or some other method or am I best to move the installation to a new location
Thanks for any thoughts

This would be the .htaccess code you'd need in the example.com/en/ folder to redirect everything to the exampletwo.com domain. Again, it would go in the /en/ folder and not the root folder for example.com
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ http://exampletwo.com/$1 [L,R=301,NC]

Related

Why I can't redirect subdomain from htaccess while having Cloudflare?

Why I can't redirect subdomain from htaccess while using CloudFlare SSL?
PS I don't know if I can paste URL here so I won't paste it to avoid removal of the question.
I'm getting this problem in Chrome (but it doesn't work in Firefox either)
error
I know there are fixes on the internet for this error but none worked for me. Is it because I have root domain connected to CloudFlare (also affects subdomains)?
What I did is:
1. created a subdomain in hosting and set its file directory.
2. in that file directory made .htaccess file.
3. inside the file
Redirect 301 / https://rootdomain/firstfolder
but it falls into redirects loop :(
With my .htaccess code, I check if the domain has the www. dub on the domain, then I redirect it to the subdomain without the www. dub on it. Also, because I don't think you want to change it, I place a 301 Redirect on it also.
I forgot to mention, usually people do not use the www. on the subdomain also, so I am guessing that you don't want people to use it either.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.domain\.com$
RewriteRule ^/?$ "http\:\/\/sundomain\.domain\.com\/" [R=301,L]
For specific url : put below code in your subdomain.domain.com's .htacess
Redirect 301 /blue-car/ http://www.example.com/cars/red-car

How to force Wordpress in subdirectory to use correct url after domain change

I have two Wordpress sites, one living in the root directory of my server, one living in a directory. Let's call them:
www.domain.com and www.domain.com/folder/
This worked fine until now, when I needed to change my domain and server. I moved my files from one server to the other, got everything running with the new domain on the new server, and then "parked" the old domain on the new server via cPanel, setting up the following .htaccess code in the root directory to handle traffic to the old domain:
RewriteCond %{HTTP_HOST} ^domain.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.domain.com [NC]
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [L,R=301,NC]
This appears to work perfectly for the "main" wordpress install, BUT, while visiting URLs for the Wordpress site in the subdirectory produce the correct results, they display the OLD url:
So, for example, if I visit:
http://www.domain.com/folder/page/
I see the content for:
http://www.newdomain.com/folder/page/ (eg. all the links etc. are correct)
But the URL still displays as http://www.domain.com/folder/page/
Nothing I do with .htaccess, etc. seems to change this. How can I force http://www.domain.com/folder/page/ to fully redirect to http://www.newdomain.com/folder/page/ not just show the content for it?

WordPress in base.example.com and accessible from example.com give me path issue in Hostgator

I have a WordPress installation at Subdomain. I wish to have the website display the site at example.com
The WordPress folder is located at base.example.com and the path is public_html/folder1/base.
If I run the site from the subdomain with home and site url pointing to base.example.com everything works fine. If I change the second url to my root example.com copying index.php (changing the path) and .htaccess to public_html/ I get the following issue:
.htacces is not writable from wordpress
tons of redirect issue
admin bar disappear (solved here Admin bar doesn't appear on the front-end of a WordPress website)
if I open the customizer I get errors (TEMPLATE ISSUE... with default wp themes everything works)
Using USERPRO Plugin to manage my user after login I'm redirect to the default wordpress login page (that means there is something missed up in url redirect) EDIT: This is the path on the login page that appear after userpro login: http://base.exaple.com/wp-login.php?redirect_to=http%3A%2F%2Fbase.example.com%2Fwp-admin%2F&reauth=1 ... I'm still waiting for an answer from the author
sometimes when I press logout it just reload the admin page.
when I visit base.example.com I'm not redirect to example.com... is this right? it shouldn't redirect me instead?
Are 5 days that I'm trying to solve it so I also wrote to hostgator support because I think I did everything in the right way but they just say they can't support issue wich came from customization....but this is not a customization, is just making work a simple wordpress installation from a subdomain!!!
Hope you can help me!
EDIT
.htaccess (both in public_html/ and in public_html/folder1/base are the same)
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %.{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
index.php (in root)
require('./folder1/base/wp-blog-header.php');
index.php (in public_html/folder1/base)
require('./wp-blog-header.php');
EDIT 2
I just get some 404 errors...
Updated question 4,5,6
Your suggestion doesn't work. 301 redirect force wordpress to find his files in public_html instead the installation folder and obviously it can't find anything giving me an error. I've also changed the url form example.com to base.example.com but nothing!
I've tried to install wordpress in a simple subfolder and all the issue disappear but as I'm stubborn I want to achieve to make wordpress working in a subdomain instead a subfolder...
.htaccess being writable is not unusual, being that the site is in a
different directory.
Tons of redirect issues isn't a question, I would need an error to help you solve that problem.
Solved by my answer at Admin bar doesn't appear on the front-end of a WordPress website.
This isn't a question, I would need an error to help you solve that problem.
You should contact the UserPro support team via their CodeCanyon account for support with their product.
What error occurs when you are unable to logout? I would need an error to help you solve that problem.
This is normal behavior. You can change this through a 301 redirect in your .htaccess within the root of the subdomain folder (not the root of your website). This code excludes /wp-content/* (for uploads access, plugins access, theme file access, etc.), /wp-admin/* (for admin access), and /wp-includes/* (for important WordPress includes access). Try this code and see what happens:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/wp-content/
RewriteCond %{REQUEST_URI} !^/wp-admin/
RewriteCond %{REQUEST_URI} !^/wp-includes/
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

Fishpig Wordpress Magento - http://example.com/blog resolves to www.example.com rather than www.example.com/blog

I have a working Fishpig Wordpress Magento instance on a production server.
All the green ticks show it has succesfully configured and when visiting
http://www.example.com/blog
it works. However when I try and and visit
http://example.com/blog
it sends me back to the magento home page at www.example.com .
I have tried setting the url in wordpress to both http://example.com/blog and http://www.example.com/blog but in both situations it always sends me to the home page at site.com.
This is a concern because most experienced web users will not type www when trying to access a location.
My htaccess is as generated by Wordpress and looks like
DirectoryIndex index.html index.php
<IfModule mod_rewrite.c>
#wp generated
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
Please not the wordpress site files are located at site.com/wp and it is the fishpig extension which arranges the direct from the non existent /blog path.
First of all, to start of, one way to resolve the issue is to simply make your Magento website DEFAULT to not have the www. in the url.
In Magento, go to System > Configuration > Web.
In the "Secure" and "Unsecure" tabs, find "Base URL."
The value should look something like this:
http://www.site.com/
Replace ALL references to the domain so it shows:
http://site.com/
Unfortunately, there may be a lot of appearances of it throughout the site. You'll need to do the same thing elsewhere on the server.
If you really want your site/blog to say www., though, you'll have to properly forward the .htaccess file in Magento. I'm not too keen on how Magento's .htaccess file works, but I do know how to forward a url and keep all of its additional pages as well (however, Magento's setup may interfere).
The code should look something like this:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^site.com$ [NC,OR]
RewriteRule ^(.*)$ http://www.site.com$1 [R=301,L]
Again, I don't know how well this will work with Magento's set up, but I've successfully used the above code to redirect url's to the correct url I want. That code above was actually used on a wordpress site, though.
Check for Rewrite rules in Magento's .htaccess file and try putting this above it. Be careful, though; it is VERY easy to cause 500 internal server errors if you mess up the .htaccess file, so always keep a backup.
Try this out and I hope it helps.

htaccess redirect to wordpress if I type domain.com/index.php

I've been trying to figure this out but no success. I have a static site in domain.com/site/index.html but I'm also creating a new wordpress version in / to eventually replace it.
What do I put in .htaccess so typing domain.com opens www.domain.com/site/index.html (static website) while typing domain.com/index.php opens the Wordpress site? Is this possible?
Edit: I deleted the previous .htaccess code I posted here. It just didn't work.
%{HTTP_HOST} is just the host name (e.g. "www.domain.com"). To test the path after the host name you need to use REQUEST_URI
RewriteCond %{REQUEST_URI} !^\/index.php

Resources