.htaccess: Point Secondary Domain to Primary's Subdirectory - .htaccess

I have two domains on a VPS server, the primary "domain1.net" and the secondary "domain2.com". The website I have currently set up for domain2.com resides at domain1.net/subd1/subd2. I'm trying to create a rewrite rule for my .htaccess file so that whenever someone visits the site "domain2.com", "domain2.com/index.php", it grabs the page from "domain1.net/subd1/subd2", "domain1.net/subd1/subd2/index.php". I would like to do this while keeping "domain2.com" intact in the web address, instead of moreover redirecting it, and have all images/links appear from domain2.com.
From my understanding, it seems .htaccess's rewrite rule would be able to do such a thing, I just haven't figured out how the syntax would work. However, if there's a superior alternate method, I wouldn't be opposed to hearing it.
I appreciate anyone's help on this issue.

Related

How do I redirect from the old domain to the new domain via an alias on the DNS of the old domain, using the .htaccess of the new one

Sorry if that question title doesn't make any sense but it pretty much captures where I'm at with my confusion here.
So I've worked on a site that we'll call new-site.com that is going to be taking over from an existing site that we'll call old-site.com
There's no cross-over between the sites necessarily, but the owners don't want the sites to both exist at the same time so they want old-site.com to redirect to new-site.com which seems fairly straightforward.
My thought process for doing this would be to add a simple redirect rule to the htaccess file of old-site.com that just forwards everything to new-site.com, job done.
What is actually going to happen is that the developer of old-site.com is saying that what we need to do is to hold all the redirects for old-site.com in the htaccess file in the public folder of new-site.com and that he will then 'alias' the old-site.com domain over to new-site.com via the old domain DNS.
This is super confusing to me and a little out of my comfort zone and I'm not sure how I'd go about writing my redirects. Should I include the full domain name for old-site.com in there every time because otherwise surely I'll end up in a redirect loop if I don't use the domain name and I want to go from old-site.com/about-us to new-site.com/about-us?
I hope that makes sense and that some more experienced hands know what I need to do and can help me understand a little better?
Thank you

How can I display a subpage of my Silverstripe website as a subdomain?

I have a website build on Silverstripe 3.
Now I want that a user can enter the Subdomain URL info.mydomain.com and see the content of the page mydomain.com/subpage-url/. But without redirection. The subdomain URL should stay in their browser.
I already created the subdomain and let it point to the root directory of my website. As I understand it right I now need some rewrite conditions in my .htaccess file? And that is the point I struggle with. I googled a little bit and did some trail and fail but nothing seems to work. Maybe I understand it totally wrong, used the wrong rewrite conditions or insert them on the wrong place.. Maybe there are Silverstripe specific issues to pay attention to?
Long story short: I need help please!
As Robbie Averill pointed out in his comment, you could install the Subsites module. But you'd have to create a Subsite (eg. a separate site-tree) for every domain.
There's another module though, the homepagefordomain module. With that module you can specify one (or multiple) domains per page. When you visit one of these domains, the page that was specified as home-page for that domain will show up. I think this is a more flexible approach than messing with the .htaccess file.

301 Redirect without hosting

I have a client who is merging two sites into one. For the time being we are just installing a WP plugin to the site to manage the handful of 301 redirects they'd like handled, rather than writing to .htaccess manually.
But in a month or two they'd like to remove the site completely. Is there a way we can redirect traffic to the new combined site once they get rid of their hosting and we no longer have access to their .htaccess?
I have seen some brief mentions of setting the DNS to something but I don't totally understand and I'm not sure if this is the right thing to do. I have not asked the client if they are holding onto the domain name. In order to point the DNS to the new site, we'd need them to still own the old domain, correct? What would I assign the values to be?
You have to own the domain to do anything with it including updating DNS name. It wouldn't be smart to let it go.
If they don't have hosting on it anymore, then they will need to do domain forwarding with DNS. It can be done with 301 or 302 status codes. This link will show you how to do it on Godaddy. If you don't have Godaddy as your registrar, just look for the instructions for your domain registar.
https://www.godaddy.com/help/manually-forwarding-or-masking-your-domain-name-422

Htaccess.. changing the domain name

I have a big Joomla website that was moved from .com to .eu domain.
The sites are on one web server.
On the old website there are a lot of links that point directly to oldwebsite.com/somethinghere.
Is there a way with Htaccess file in the old domains folder to redirect
from oldwebsite.com/somethinhere to newwebsite.eu/somethinghere?
Or maybe a way to do this on the new website folder?
Thank you,
Chris.
There are many ways, some people recommend using RewriteEngine, but there is an easier way:
Redirect 301 / http://domain.eu/
This will automatically handle files in the domain -- for example, old.com/foo will be redirected to new.eu/foo
EDIT: Regarding "301", that is the code for a permanent redirect. There also exist temporary redirects (I believe the code is 302), but it sounds like what you need is exactly this - a permanent redirect.
EDIT2: Oh and, I think the / after domain.eu may be required, but I'm not 100% sure - doesn't hurt for it to be there, that's for sure! I know that because I use the same kind of a redirect on a production website.

Google juice with subdomains and porting an application using rewrite rules

Background: I've got a web app on sub.domain.com. My primary website is on domain.com. My sub.domain.com pages are stuffed with keywords that I would like to use to get upped in pagerank on domain.com. however, the whole app has been written on sub.domain.com, and it'll be some effort to host it at domain.com/subdirectory, due to how URLs are written, etc.
First question: would you expect that migration (from sub.domain.com to domain.com/subdirectory) to substantially improve the pagerank of domain.com over how it is now? I've done a lot of research, and opinions are split on if google with link the subdomain with the main domain.
Next question: if I do want to do the migration, it'll be difficult to do in the actual codebase (more tedious than difficult). Does anybody have some advice for how I could do this with mod_rewrite? I know there has to be a clever way to do it, but I can't even start to sketch out a solution. Maybe this means it's not a good thing to do, but I was hoping for kind of a quick hack, rather than rewriting all my URLs. Plus, I would like it to be pretty easily reversible, which wouldn't be the case if I change my URLs (dev is ongoing, so it's not as simple as just rolling out a previous version).
Pagerank isn't a property of domains, it's a property of individual documents. So it'd be more accurate to say that migration from sub.domain.com to domain.com/subdirectory will improve the pagerank of domain.com/subdirectory. If you're concerned solely about the ranking of the domain.com home page, the impact on that will mostly depend on your internal linking. For example, if all pages on sub.domain.com currently have a "home" navigation link that leads to the home page of sub.domain.com, and when you do your move they'll now lead to the home page of domain.com, then this will contribute to the domain.com home page's ranking. If this "home" navigation link went to domain.com/subdirectory, on the other hand, then that's what they'll be contributing pagerank to.
mod_rewrite doesn't change the outbound links in your HTML, it changes how inbound links are interpreted. So it would let you put this in the virtual host file or .htaccess for sub.domain.com:
RewriteEngine on
RedirectRule (.*) http://domain.com/subdirectory/$1 [R=301]
to mass redirect any requests coming in on sub.domain.com where they need to go. It won't help you produce correct new-form URLs in your codebase. (You could, in theory, leave all your links how they are and rely on the 301 redirect to keep you from having to change them, but this is really sloppy and wasteful, generating two HTTP requests instead of one for no good reason).

Resources