I have hosted my website using WHM and Cpanel,
and added following lines to .htaccess file
RewriteCond %{HTTP_HOST} ^103\.241\.144\.130
RewriteRule (.*) http://www.rockinexams.com/$1 [R=301,L]
now, this:
http://103.241.144.130/~rockinex/
redirects to www.rockinexams.com but 103.241.144.130 does not.
I heard that this does not work due to something related to cpanel architecture.
Is there any way I can achieve it?
If that IP is a shared IP, your rule will not work. For this rule work, you need a Dedicated IP to access just http:YOUR-IP. You even can try to put the ~rockinex on rule, but I don't think it will work.
Related
I have 2 domains, the first is old, not hosting assigned and redirects to the new domain, in which a prestashop with friendly urls is installed.
www.olddomain1.com >> www.newdomain2.com
The problem is when there are parameters in the old domain and want to redirect the new domain with the friendly url.
www.olddomain1.com/shop/home.php?cat=74 >> www.newdomain2.com/cat=74
As I can do redirections so that:
www.olddomain1.com/shop/home.php?cat=74 >> www.newdomain2.com/pillows
That way I can set this up? Is there any way that is not hosting the old assign a domain?
First you need to configure DNS CNAME record for www.olddomain1.com that is pointing to www.newdomain2.com. That way all requests for www.olddomain1.com will go to your new web server.
Next, you need to configure your new webserver to respond to requests that have Host: www.olddomain1.com header.
If above two steps are done, all you need is mod_rewrite rule, but you need to provide exact and precise explanation what is being rewritten to. if all you need is www.olddomain1.com/shop/home.php?cat=74 >> www.newdomain2.com/cat=74, then this should do:
RewriteEngine On
RewriteBase "/"
RewriteCond %{HTTP_HOST} www.olddomain1.com
RewriteCond %{QUERY_STRING} cat=(.+)
RewriteRule shop/home.php http://www.newdomain2.com/cat=%1? [R=301,L]
I have a domainname, www.X.com that redirects (using some magic from the webhosting-company from which I bought www.X.com) any user that visits www.X.com to www.Y.com/test.
This works fine, but what I would like to happen is for the URL to remain www.X.com after the redirect. Right now, after the redirect the users URL changes to www.Y.com/test.
I'm not sure if htaccess rewriting at www.Y.com can fix this issue, so I would like to know wether this is possible and if so, how do I implement it in my .htacces file?
Regards and thanks in advance,
Robert
Instead of using the redirect tool of your hosting provider. You have to configure your domain to point to your server with a DNS A record:
Domain Type target server
www.X.com. A x.x.x.x
www.Y.com. A x.x.x.x
In your server virtualhost or via your hosting provider you need to configure both domains to point to your website.
In your .htaccess file you need ton configure domain www.X.com to point to the test directory:
RewriteCond %{HTTP_HOST} ^www.X.com$
RewriteRule ^(.*)$ /test/$1
Problem was solved by clearing out my Chrome cache; The webhost-magic HAD done the trick. Thanks mr Rockett and mr Lemaitre for your time!
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]
I have three domains like www.example1.com, www.example2.com and www.example3.com.
i have pointed these domains to www.adminwebsite.com through CNAME, A and Name Server.
It is working fine.
I need to redirect
www.example1.com
to
www.adminwebsite.com/index.php?website="www.example1.com"
Is it possible through .htacces or any way?
Untested but should work, give it a go:
RewriteCond %{HTTP_HOST} ^(www\.example1\.com)$
RewriteRule $^ http://www.adminwebsite.com/index.php?website=%1 [R=302,L]
Keep in mind that if your adminwebsite domain is not the default domain of the server you will still need to configure the example1 domain on the HTTP server otherwise it won't work or if you have cPanel you will have to create an addon with it.
I have a hobby website for a number of different projects and want each project to have it's own subdomain, like foo.domain.com, bar.domain.com etc.
I use Drupal with the Domain Access module, meaning all subdomains should point to the base installation of Drupal, and then the module recognizes what subdomain the request comes from and serves a page according to that.
Now, since this is just a hobby project, I keep it on a free shared hosting account, which means a few limitations:
No wildcard subdomains.
Each subdomain is linked to a subdirectory with the same name, for example domain.com goes to /public_html/ and sub.domain.com goes to /public_html/sub/ The hosting forces this.
I can't create symlinks.
I have limited space and databases, meaning I can't just make a new installation for each project. (Hence the Domain access module)
My domain registrar (Godaddy) doesn't play nice with shared hosting. I tried hosting the DNS with them and doing a wildcard A record to my hosting server, but it didn't work, and Godaddy don't allow wildcard CNAME records for some reason...
It seems the only option left for me is some .htaccess magic.
I need a .htaccess file to put in the subdomain director(y/ies) to tell apache:
The data is in the root web directory
To not change anything else, so that the Drupal module knows what subdomain was requested and the user still sees "sub.domain.com" in the browser window.
Thankful for your help!
TL;DR
How can I tell Apache to use the data from another directory (i.e. /public_html/ instead of /public_html/subdomain/) WITHOUT making a redirect or any changes to the headers? HTTP_HOST needs to be intact.
Thanks!
Try this:
http://kb.mediatemple.net/questions/242/How+do+I+redirect+my+site+using+a+.htaccess+file%3F
try this
RewriteEngine On
RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com%{REQUEST_URI} [R=301,L]
try this.
RewriteEngine On
RewriteCond %{HTTP_HOST} sub\.example\.com$ [NC]
RewriteRule ^sub/(.*)$ $1 [L]
Not sure if it will work, because I don't know how your host configured to server to map the subdomains to a different folder.
Otherwise you could try the Proxy flag, but that will not set the correct http_host variable in php.
Are you sure Drupal doesn't have a different method of doing multiple installs. I know WP did have a option to use a prefix for all table-names so multiple installs can coexist, using the same database, as long as they use different prefixes. Not sure how big a Drupal install is, and what amount of diskspace your host provides.