On shared hosting subdomain not point to my website's folder on server - apache

I have my website host on shared hosting server where other websites are also hosted.
Now I want to subdomain to point my website's folder on server.
Means if we go to the URL coolname.domain.com then it should be redirect to www.domain.com.
But It's redirected to Cpanel error page.
Thanks in advance.

The best way to do that is to set an entry in your DNS zone for your subdomain.
You can also use URL Rewriting in a .htaccess file :
RewriteEngine on
RewriteCond %{HTTP_HOST} ^sub.domain.com$
RewriteRule (.*) http://domain2.com/$1

Related

Apache virtual hosting url redirect from one domain to other domain without showing the url in the browser

Apache virtual hosting url redirect from one domain to other domain without showing the url in the browser?
That's not redirect, that's called Reverse Proxy.
Example:
ProxyPass /url-path/ http://backend.example.com/url-path/
This will reverse proxy all requests to /url-path/whatever to the server backend specified
More information at:
http://httpd.apache.org/docs/2.4/mod/mod_proxy.html
http://httpd.apache.org/docs/2.4/howto/reverse_proxy.html
No, there isn't a way to do this with .htaccess if your sites are on different servers. Doing so would present big security hole, imagine if someone does this with a bankĀ“s website.
However, if both are hosted on the same server try this on your .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain1.com$ [OR]
RewriteCond %{HTTP_HOST} ^http://www.domain1.com$
RewriteRule (.*)$ http://www.domain2.com$1 [P]
</IfModule>
If you own both domains you could accomplish this with domain name forwarding. Check the options in your registrar (maybe godaddy, or dns managers like cloudflare).

htaccess redirect https traffic to a specific folder?

I am hosting my website on godaddy and recently purchased an SSL cert so I can also run https traffic. However, I want all https traffic to go to a specific folder that regular http cannot get to. In addition, I don't want the specific folder to be a sub-folder of the main http document root.
GoDaddy cPanel folder structure:
/home/myAccountFolder/
/cache
/logs
/public_html
/private_html
...
By default, all standard http traffic for "www".foo.com will go to /public_html - but how can I get all traffic for https://api.foo.com to map to the /private_html folder?
I am told that .htaccess can do this but can't seem to locate how to do this. I know I could redirect https to /home/myAccountFolder/public_html/secure, but I want it going to /home/myAccountFolder/private_html - a completely different root folder.
Also, I don't have access to the server configuration or (that I am aware of) have the ability to create/manage virtual hosts within GoDaddy's cPanel enviornment. All I can do is control directories and what goes into my websites .htaccess file.
Inside your site root .htaccess you can use this rule to redirect api.foo.com to secure/ folder:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^api\. [NC]
RewriteRule !^api/ api%{REQUEST_URI} [L,NC]
Inside your api/.htaccess you can use this rule to allow only http://api.foo.com:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^api\. [NC,OR]
RewriteCond %{HTTPS} off
RewriteRule ^ - [F]
# rest of the rules

Redirect for path but only for specific domain

We have different domains that are hosted on our server. Recently one of the main sections of our site has been moved to another server and been given a subdomain:
http://www.mysite.com/store
Has been moved to
http://store.mysite.com
Within our apache VirtualHost we wanted to redirect all traffic from the old domain to the new one:
Redirect permanent /store http://store.mysite.com
The problem is, we have other hosted sites that are being redirected now:
http://www.othersite.com/store
http://api.greatsite.com/store
We don't want this. How can I only have apache do redirects if http://www.mysite.com/store which has the /store path, and ignore other domains with /store?
Use mod_rewrite based code:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.mysite\.com$ [NC]
RewriteRule ^/?store(/.*|)$ http://store.mysite.com [L,R=301,NC]

htaccess : how to redirect all files in a folder to non subdomain if accessed via a subdomain?

using htaccess, I need to remove the subdomain part of the url if a file is accessed in /folder/myfiles/
eg. I need to redirect
sub.domain.com/folder/myfiles/anyfile.php
to
domain.com/folder/myfiles/anyfile.php
any file found in /folder/myfiles/ if accessed via a subdomain must be redirected to the same file on the root domain.
background: the site uses subdomains for wordpress blogs on multisite. There is a 3rd party app installed to a folder on the root domain, the licence is only valid for the root domain and attempting to access it via a subdomain invalidates the licence so I need to make sure that any file in that folder must only be accessed via the root domain and not a subdomain.
In the folder's .htaccess:
RewriteCond %{HTTP_HOST} sub.domain.com
RewriteRule (.*) http://domain.com/folder/myfiles/$1
In the root .htaccess or server config:
RewriteCond %{HTTP_HOST} sub.domain.com
RewriteRule ^/?(folder/myfiles(/.*)?)$ http://domain.com/$1

Redirect from one domain to another, without the user realizing it

I have a bunch of domains on on of my servers. I'd like to be able to redirect some domains to a different domain without the user knowing, so not a 301 redirect.
An example, redirect domain.com to masterdomain.com/sites/domain.com. So when visiting domain.com, the user would be displayed with the data on masterdomain.com/sites/domain.com.
Also masterdomain.com and domain.com are on the same server.
How could I do this using Apache? mod_rewritem mod_alias?
If both host names use the same document root, you can do this:
RewriteCond %{HTTP_HOST} =example.com
RewriteRule !^sites/example\.com(/|$) sites/example.com%{REQUEST_URI} [L]
This rule will prepend /sites/example.com if the requested URI path does not already starts with that.
GoDaddy calls this a domain Alais.
Here is a link where it is explained
http://webwizardworks.com/web-design/domain-alias.html