Sub-domain forwarding with masking via .htaccess - .htaccess

My sub-domain sub.domain.com is forwarding (redirecting) to another.website.com correctly. However, I want to enable masking, meaning that after redirecting I want my sub-domain to show in the address bar rather than the other domain, while still showing the other domain's page content.
What should I put in the .htaccess file in order to perform this action?
Also, note that the .htaccess file is under my domain's file manager in cpanel and not subdomain's (maybe that's a given for you, but bear with my basic knowledge please...).
Should you need any more information do not hesitate to point it out please.
Thanks in advance!!

You should check the mod_proxy module, the ProxyPass directive and ProxyPassReverse directive. Put these directives in config file:
ProxyPass / https://another.website.com
ProxyPassReverse / https://another.website.com

Related

Redirecting web content but not the name of web page address

I have two internet addressess, say one.com and two.com
The content of my webpage is all under the domain one.com. If I hit address two.com I want it to redirect to one.com but still with address two.com. For example if I type in address bar two.com/article. I want to still show this same address but the content displayed would be as from address one.com/article
I tried to use htaccess file, but still no luck.
Any advice would be appreciated.
You can't achieve that while performing an external redirect.
If both domains are hosted on the same server, then you can perform an internal redirect (e.g. using Apache's Alias, AliasMatch or mod_rewrite).
If the domains are hosted on different servers, then you would have to proxy one of them. You could do this with ProxyPass from Apache's mod_proxy.
Go to your domain name provider and create an alias (CNAME record) for the address.
You will need to enable mod_proxy in your Apache config for that. Once mod_proxy is enabled, enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory on domain2.com host:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.domain2\.com$ [NC]
RewriteRule ^ http://www.domain1.com%{REQUEST_URI} [L,P,NC]

Linking one domain to another domain with htaccess

I'm stuck with htaccess redirect on this case:
I have myapp.com domain where my main website and service runs on. My customers logs into their accounts on myapp.com and use. Now, I am going to provide one of the features on a separate domain, let's assume "goto.com". However, I don't want to build a separate app on goto.com. I just want to redirect all coming requests to goto.com to a php script under myapp.com but this redirection should be in the backend (masked), not a 301 redirection.
Let me clear up:
myapp.com - /var/www/vhosts/myapp.com/httpdocs/index.php
goto.com --> masked redirection --> myapp.com/goto.php?$1
How can I do this with htaccess? Any suggestions?
Just found that it can be done with redirect [P] (proxy) method: RewriteRule ^(.*)$ http://myapp.com/public_view/$1 [P] What do you think? Is this a good and stable method?
That method is fine, it utilizes the mod_proxy module. The only thing I can suggest is adding the L flag as well in case you have other rules in your htaccess file.
A limitation with using the P flag in an htaccess file is that if a page or request to http://myapp.com/ redirects, then you're URL address bar will say http://myapp.com/ instead of your other domain. The only way around this is to use ProxyPassReverse but it doesn't work in an htaccess file. You'd need access to vhost config:
ProxyPass / http://myapp.com/public_view/
ProxyPassReverse / http://myapp.com/public_view/
Additionally, if http://myapp.com/ sets cookies, you'll need to use the ProxyPassReverseCookieDomain and ProxyPassReverseCookiePath directives to rewrite those.

URL masking (?in .htaccess) from one domain to another

I've been searching the archives but I can't find anything that is making too much sense to me.
I have a site with a couple of subdomains which redirect to other sites.
E.g.
the visitor types - www.jmp.redtwenty.com.au - and is redirected to - http://creator.zoho.com/redtwenty/jmp-conversion-tracking
Is there any way to mask this redirect so that the visitor still sees jmp.redtwenty.com.au in the address bar?
I keep seeing mention of a rewrite rule in .htaccess but not sure if that is what I want.
Thanks
Mike
You can do this a few ways, but you'll need to make sure mod_proxy is enabled.
If you have control of the server config or the vhost config of the www.jmp.redtwenty.com.au/ domain, you can add this to it:
ProxyPass / http://creator.zoho.com/redtwenty/jmp-conversion-tracking/
Or in the htaccess file in the document root of http://www.jmp.redtwenty.com.au/:
RewriteEngine On
RewriteRule ^(.*)$ http://creator.zoho.com/redtwenty/jmp-conversion-tracking/$1 [L,P]

.htaccess rewrite full domain name

Are there anyway to make a user get to download thefile by let them type:download.mywebsite.com/thefile
in the browser address while the "download.mywebsite.com/thefile" does not exist but the "www.mywebsite.com/thefile" does.
I've got nearly zero knowledge with .htaccess and mod_rewrite engine. I hope my question is clear.
IF you own mywebsite.com then yes you could, you would have to place a ServerAlias in your root httpd.conf directive then use mod_rewrite to re-write all requests for download.mywebsite.com/thefile to www.mywebsite.com/thefile but the mod_rewrite would not know if a file exists or not in advance.
Another way to do it would be implement a custom error document for a 404 handler which redirects a user to a suggested URL.
RewriteEngine On
RewriteRule ^/download/(.*)$ http://download.mywebsite.com/$1 [R=301,L]
You need to set up your web server to listen for sub-domains as well

redirecting without changing URL

i want to redirect domain domain1.com to domain2.com completely but without changing domain1.com URL.
i thought i could do that with .htaccess but i found out that it is not possible because they are to different domains and i should use http:// in .htaccess rule so it would be an external rewriting not an internal rewriting,so the URL will change.
is there any other solution? is using iframe the only solution?
i have to add that i don't want to change DNS setting for these 2 domains.
If both domains point at the same server then you can setup your apache config to point both domains at the same document root.
NameVirtualHost *
<VirtualHost *>
ServerName domain1.com
DocumentRoot /www/mysite
</VirtualHost>
<VirtualHost *>
ServerName domain2.com
DocumentRoot /www/mysite
</VirtualHost>
However, I would recommend domain2.com redirects (with a 302 redirect in the .htaccess) because it will improve your search engine optimisation, as both sites will be considered as one. So if a GoogleBot finds domain2.com as a link in another site, it will add it as a pagerank to domain1.com.
If they run on the same webserver you could set domain2 as an ServerAlias for domain1.
I thought I once read you could give a flag to mod rewrite that it internally proxies the request to another domain, however I have never used this myself (if it even exists) and I can't honestly say I think it'll be great for performance.. (but maybe it is..)
But why would you want two different domains show the exact same website, without changing the hostname to, what you see as, the primary one. If I might ask?

Resources