Redirecting web content but not the name of web page address - .htaccess

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]

Related

Map domain name to a space on the server

I have a domain, e.g., domain.org and a hosting space on the server that has the address http://server/node/myname.
How I can map domain.org to http://server/node/myname such that when I visit to domain.org/some/path I go to http://server/node/myname/some/path?
The domain service offers me web forwarding with HTTP/301 Forwarding or Cloaking Forwarding but none of them works for me. They simply redirect me to http://server/node/myname when visiting domain.org/some/path.
If you have access to apache config It would be Directory config within your VirtualHost config part. see https://wiki.ubuntuusers.de/Apache/Virtual_Hosts/
You can write redirects within your site like here:
https://en.wikipedia.org/wiki/URL_redirection
Modify your .conf file if you have access to Apache configuration like this...
RewriteEngine on
RewriteRule ^(.*) http://server/node/myname/$1 [P]
This will redirect all traffic for the base URL you set above this in that configuration file.
If you already have a rewrite rule in place for domain.org you can use scripting within those pages to do simple URL redirects by parsing the URL on domain.org into a new string for http://server/node/.

Masking sub domain with a new domain while preserving the paths

I own a domain since long, just masking the names:
http://mydomain.com
Later I started using a subdomain on this domain for some project.
http://subdomain.mydomain.com
Those projects grew and now I have a structure like
http://subdomain.mydomain.com/project1
http://subdomain.mydomain.com/project2
http://subdomain.mydomain.com/project3/subproject1
http://subdomain.mydomain.com/project3/subproject2
http://subdomain.mydomain.com/project3/subproject3
http://subdomain.mydomain.com/project4
....
etc.
now I bought a new domain (shortdomain.com) where I plan not to move anything but everything should be accessible via redirects so everything looks like:
http://shortdomain.com
http://shortdomain.com/project1
http://shortdomain.com/project2
http://shortdomain.com/project3/subproject1
http://shortdomain.com/project3/subproject2
http://shortdomain.com/project3/subproject3
http://shortdomain.com/project4
...
etc.
So basically I need to do two things:
1. if anyone visits my old domain, redirect them the new naming structure. i.e. if someone loads http://subdomain.mydomain.com/project2 they should be redirected to http://shortdomain.com/project2
when a user loads/redirected to http://shortdomain.com/project2 this should actually load the content present at http://subdomain.mydomain.com/project2
So I will not manually migrate projects,codes and GBs of other data. I think this might be acievable by smart redirection only.
Just FYI:
1. I have full DNS control of both the domains
2. I am hosted on hostgator
3. I use cloudflare on the first domain and would like to continue using it
I think this might be acievable by smart redirection only.
No, redirection changes what's in the browser's location bar. If you redirect to shortdomain.com then the request will get sent to shortdomain.com, and have nothing to do with subdomain.mydomain.com anymore. If you redirect back to subdomain.mydomain.com, then the location bar in the browser will change as well.
What you really want to do is point shortdomain.com to the same server and document root that subdomain.mydomain.com is on. Then use this to redirect (either in htaccess file or server config):
RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain\.mydomain\.com$ [NC]
RewriteRule ^(.*)$ http://shortdomain.com/$1 [L,R=301]
If, for whatever absurd reason you can't point the shortdomain.com DNS to the same webserver that serves subdomain.mydomain.com, or can't setup that webserver to accept requests for the shortdomain.com host, you need to setup a proxy server. And it'll work something like this:
2 Webservers, server A (hosts subdomain.domain.com) and server B (hosts shortdomain.com)
Someone requests http://subdomain.mydomain.com/project3/subproject1
server A gets the request and redirects the browser to http://shortdomain.com/project3/subproject1
browser's location bar changes to new location
server B gets the request and reverse proxies the request back to server A
server A gets the request again but must recognize that it is a proxy and then serve the page instead of redirecting
As you can see, this is a horrendously ineffecient solution. It's also a high possibility that your hosting service won't allow you to setup proxy servers.
I have full DNS control of both the domains
With full control I assume you can enable mod_proxy as well on Apache web-server of shortdomain.com. Once that is done set it all up this way.
On subdomain.mydomain.com enable mod_rewrite and place this rule in Apache config OR DOCUMENT_ROOT/.htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain\.mydomain\.com$ [NC]
RewriteRule ^ http://shortdomain.com%{REQUEST_URI} [L,R=301]
On shortdomain.com enable mod_proxy, mod_rewrite and place this rule in Apache config OR DOCUMENT_ROOT/.htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^shortdomain\.com$ [NC]
RewriteRule ^ http://subdomain.mydomain.com%{REQUEST_URI} [L,P]

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]

Showing page from different domain for certain url?

I have a page on my site, mysite.com/test, that I want to load a page on another site, test.jit.su, for example. I had set up my nameservers with my registrar (godaddy) so that I could add an A record for mysite.com/test that would point to test.jit.su. This has posed a few problems with email and other things on my webhost, so I'm going to change the nameservers to those of the webhost.
Is there still a way to do this without the A records?
DNS records can only set an alias on a domain (of any level), e.g. mydomain.com --> yotherdomain.com
which also automatically implies redirects like
mydomain.com/anything --> myotherdomain.com/anything
but you can not do mydomain.com to one server and mydomain.com/anything to another server, if you want to do this you'll have to use HTTP redirect
Changing A record will not resolve your issue as noted by #unleashed-dev.
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:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
# proxy /test to http://test.jit.su/test
RewriteCond %{HTTP_HOST} ^(www\.)?mysite\.com$ [NC]
RewriteRule ^(test)/?$ http://test.jit.su/$1 [L,P,NC]

Resources