.htaccess to rewrite to subfolder & different URL - wordpress

I've got a site that's setup as a WordPress network/subsite off primary url.
domain.org/subsite
I'd like to rewrite requests from a seperate DNS name - call it domain2.org - (which I control) to that subsite
domain2.org -> domain.org/subsite
I've seen examples of using .htaccess rewrites to route to subfolder, but can't figure out specifics on how to do this.
Thanks for looking.

put this code in your DOCUMENT_ROOT/.htaccess file of domain2:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domain2\.org$ [NC]
RewriteRule ^ http://domain.org/subsite%{REQUEST_URI} [R=301,L,NE]

I had an experience working with wordpress multisite which is hosted at godaddy.
Godaddy has an option for the registered domain say for eg http://domain2.org asked for hosting server point or url. In the url field paste it http://www.domain.org/subsite
So check with your hosting provider.

Related

mask domain in url using .htaccess

Heya thanks for any help in advance
So i have 2 domains both with same hosting company namesco called dmfoundation.org.uk and dmtrust.org.uk.
dmfoundation.org.uk(no cpanel is apache http server) has all the files for my wordpress site and dmtrust.org.uk (cpanel) has no files inside it.
what i want to do is redirect dmtrust.org.uk to dmfoundation.org.uk but i want all the urls to appear as dmtrust.org.uk/whatever file name.
rather than displaying dmfoundation.org.uk/whatever filename.
any question feel free to ask.
Cheers,
Grant
First you'll need to point DNS from dmtrust to dmfoundation hosting.
Then in wp replace the site url to dmtrust (and eventually all links/src to dmfoundation in database).
Finally, in your .htaccess, at the root of you wp on dmfoundation, add a redirection to match every pages.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(.*)$ http://dmtrust.org.uk/$1 [R=301,L]
</IfModule>

Moving WordPress from subdirectory to new domain

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]

Masking domain using htaccess wordpress

Two websites, both WordPress installations.
Old Website is hosted with provider A with their real domain - website.com.au (not real address obviously)
New Website is hosted with provider B and has temporary domain - lotsofcrazynumbers.com.au
In the process of transferring domain over to provider B but they can't wait for that to happen and have asked me to fwd their real domain over to New Website.
So I edited .htaccess in Old Website's admin area to fwd to New Website's temporary domain but of course the temporary domain is displaying, which will freak out their customers.
I used the following in the .htaccess
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^/?$ "lotsofcrazynumbers.com.au" [R=301,L]
I know that I probably haven't set this up right but domains and DNS is not really my thing. Is there anyway that I can mask the temporary domain so that it looks like their normal domain until the domain transfer has been finalised?
Any help would be appreciated..
mod_rewrite's [P]roxy option might work:
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^(.*)$ "http://lotsofcrazynumbers.com.au$1" [P,L]
Set the above in the .htaccess file of Old Website, and it should proxy any requests to New Website without change the URL in the browser.
Make sure to test properly though. :-)

static to static url rewrite with htaccess with wordpress

I have a wordpress site with its own .htaccess automatically generated (because I'm using permalinks), than, my web-admin has configured apache to redirect any third level domain to my site, ie :
http://lol.example.com redirects to http://example.com
and than .htaccess with permalinks rules does the rest.
Now I want to write a rule in the .htaccess file that, when a user types a specific third level domain, redirects to a specific subfolder of my site, ie:
http://sprock.example.com/ redirects to http://example.com/mysprockfolder/
I know my question might sound weird, but I've never done this before so I'm quite confused.
Solved with that regex in my .htaccess:
Right before this comment (just in case you have WordPress installed):
# BEGIN WordPress
I've added the following:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?thirdlev\.example\.com [NC]
RewriteRule ^(.*)$ http://example.com/myfolder/ [R=302,L]
with a 302 redirect, everything is good!
it would be much easier for you to just go to your ftp manager and make a subdomain forward to a link. Or, you can make a redirect using php.
when redirecting make sure to add the http://www. or it will think you want to redirect to a part of your page on the site, also make sure that your subdomain has its own folder with its own files and images.

Map Domain to WordPress Page

Is there a way to map a domain name to a WordPress page?
For example, if I have mydomain.com/about/bio and mydomain.com/about/resume, could I map anotherdomain.com to the about page so I could use anotherdomain.com/bio and anotherdomain.com/resume?
Additionally, could I do it with a subdomain too?
Using the same example above, could I map about.anotherdomain.com to mydomain.com/about?
With WordPress, these aren't physical folders. They're pretty permalinks, so I'm having trouble figuring out how to make this work.
We have a Plesk control panel.
Thanks for any insight you can provide!
Edit:
The domains that I'd like to map to different parts of the URL may be registered from various providers.
You can achive this using the .htaccess file....
Just point the A record of your domain names to your domain. Now do the following...
RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com
Rewriterule ^(.*)$ http://mydomain.com/about/bio [L]
RewriteCond %{HTTP_HOST} ^(www.)?myresumedomain.com
Rewriterule ^(.*)$ http://myresumedomain.com/about/resume [L]
RewriteCond %{HTTP_HOST} ^(www.)?anotherdomain.com
Rewriterule ^(.*)$ http://anotherdomain.com/bio [L]
Two possibilities you can explore:
A/ Using the plesk (or other registrar), you could try a wild-card redirect such as:
anotherdomain.com -> mydomain.com/about // with "wildcard" set to "yes".
B/ If that fails, you can create a simple redirect (anotherdomain.com -> mydomain.com) and then in WordPress (assuming it's living at mydomain.com), manually redirect individual URLs using the Redirection Plugin.
You would create individual rules like:
anotherdomain.com/bio -> mydomain.com/about/bio
C/ Finally, WordPress has become so good at redirecting broken links that you might be able to get away with simply redirecting the anotherdomain.com to mydomain.com and seeing if wordpress serves the correct page when an approximate URL is entered.
anotherdomain.com -> mydomain.com // this is the redirect you create
when people type anotherdomain.com/bio, WP might serve mydomain.com/about/bio auto-magically
Good luck!
if was me, I would do by 2 ways:
Domain forward domain1 -> domain2/about-page
Create a index.html and create a sub-folder on domain1 (ex: domain1.com/about) then linked to it. - Index.html will use iframe to call domain2/about.

Resources