Bit of a weird one.
One of my clients has a shared hosting server which he hosts his website on lets say:
http://www.example.com
To develop a web application for him I have had to use a different server lets say 255.255.255.255 which allows SSH access.
My client wants http://www.example.com/portal to essentially "point" or display the portal & web pages etc from server 255.255.255.255.
I know you can point domains but I have no idea where to start on something like this, any help or suggestions would be appreciated
J x
Better: place it on a subdomain: http://portal.example.com
Worse: proxy all request from http://www.example.com/portal to your site. But you need access to web server config - unlikely shared hosting will allow you to do it.
Or you need your own hosting like VPS and so on.
A plain 301 redirect comes to mind:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} www.example.com/portal$ [NC]
RewriteRule ^(.*)$ http://255.255.255.255/$1 [L,R=301]
This should obviously go into the .htaccess on www.example.com
Add this to .htaccess file placed in the root of the www.example.com site:
RewriteEngine On
RewriteRule ^portal/?(.*)$ http://255.255.255.255/$1 [P]
Related
Maybe I'm not using the right technique for the task (and if you have any suggestion for what I'm trying to achieve, that would be welcome too).
I have an app on Heroku at http://some-app.herokuapp.com. I own the domain some-app.com and it is currently pointed to a shared host (where I receive emails #some-app.com and store static files in http://assets.some-app.com).
In order to redirect the domain to the app on Heroku, I added a new CNAME on my shared hosting for www.some-app.com that redirects to http://some-app.herokuapp.com. That works well.
Now, if I navigate to http://some-app.com, I don't get redirected (which is normal, the 'naked' domain name points to my shared hosting). So, on my shared host, within some-app.com/public_html/ I added the following index.php file:
<?php
header("Location: http://www.some-app.com");
That works well, http://some-app.com redirects to http://www.some-app.com which in turns, through the CNAME correctly opens http://some-app.herokuapp.com, keeping www.some-app.com in the address bar of the browser.
Where I am stuck is this: although http://www.some-app.com/some-dir/ works well, http://some-app.com/some-dir doesn't redirect. Instead, I get a 404.
How to handle this properly while keeping my emails and static files on the shared hosting (cpanel based, if that helps).
Thank you.
After a lot of searching, I found the most elegant way to do this. Place a .htaccess file at the root of public_html with the following content:
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
I've made a new website for a client who has an intranet integrated into their old website.
The new website is currently on a different server, but when the domain A records point to the new server, the old site (and intranet) will obviously not be accessible, but I need to keep their intranet active. The path to their intranet is: abc.com/intranet
Is there a way to have URL path direct to the old server? For example:
abc.com - new website loads on new server
abc.com/intranet - old website loads on older server
If it's not possible, I suppose I'm looking at creating a sub-domain on abc.com for the intranet. Any thoughts are appreciated.
You need to use an Apache RewriteRule using mod_rewrite. This can be placed in an .htaccess file on your server’s root or it can be placed directly into your Apache config file.
If you want to redirect example.com to example.com/intranet, then this is the Apache RewriteRule that should work for your needs:
RewriteEngine on
RewriteRule ^(.*)$ /intranet [L,R=301]
This will grab any URL on the site this RewriteRule is placed on & redirect them to /intranet. That /intranet can also be a full URL such as this example below:
RewriteEngine on
RewriteRule ^(.*)$ http://example.com/intranet [L,R=301]
EDIT: Upon rereading your question, I am not 100% sure the answer above works for you as-is. So I think if you are describing how to point one URL path from one server to another, you would do this. This gets placed on the new server:
RewriteEngine on
RewriteRule ^/intranet(.*)$ http://old_example.com/intranet [L,R=301]
That would grab any URL coming from new_example.com/intranet and redirect it to old_example.com/intranet.
ANOTHER EDIT: Since the original poster indicates the server will have the IP fully changed, then a subdomain for the old server is the best way to go. You can’t redirect content on one domain the way you describe if you switch the domains fully to different IP. Both servers need to be active with an active—but different—domain name for what you want to happen.
abc.com/intranet is a path in the virtual file system exposed by your web server, so is not possible to serve the content from different web server. You have 2 options here.
Put a reverse proxy in front of both servers and get the content from server A or B based on the original client request.
As you said, create a subdomain and also redirect /intranet to the new subdomain.
Hope this help!
If I enter the following link in the browser.
http://sub.domain.com then it will open http:/domain.com/page.php?c=sub and in the browser address bar visitors will see http://sub.domain.com.
I know it can be done by rewrite url. Can anyone please tell me the htaccess codes?
Quite contrary, it cannot be done by rewriting url.
You need to set up
DNS server (to direct all subdomains to your server)
and web-server (to accept them).
Yet you don't need no query string nor rewriting, as you can always easily have your domain from HTTP_HOST variable.
I think you should do it in two steps.
step 1:
If you have direct access to your control panel, you should go in it and create a general virtual subdomain using asterisk *
After this step you can use sub.domain.com. if you don't have acees to control panel, ask admin to do it for you.
step 2:
You should edit .htaccess file with below line
# Extract the subdomain part of domain.com
RewriteCond %{HTTP_HOST} ^([^\.]+)\.domain\.com$ [NC]
# Check that the subdomain part is not www and ftp and mail
RewriteCond %1 !^(www|ftp|mail)$ [NC]
# Redirect all requests to a php script passing as argument the subdomain
RewriteRule ^.*$ http://www.domain.com/page.php?c=%1 [R,L]
I hope, this helps you
i'm trying to allow only my domain name to view my website...
i have a dedicated ip and Anyone can basically set your domain to my ip, It creates duplicate content of my website.
Try this code, it will rewrite all domain names used to access your site to the correct one:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
This means that everything that do not match the www.domain.com will be redirected/rewrited to www.domain.com.
Am I understanding you correctly that you are worried that other people will point their domain to your IP, thereby lowering your SEO ratings? First of all: wow. Secondly: configure the web server with virtual hosts to respond to a particular domain name only, not to all requests regardless of HTTP Host header. How to do this exactly depends on what web server you're running exactly and whether you can configure virtual hosts on it.
As far as i know the host will only respond to the correct domainnames configured.
You could also make sure with htaccess that all incoming request get rewrited to the correct domain.
As in this example .domain.com is rewited to www.domain.com and will never be available the other way arround.
http://www.tech-recipes.com/rx/296/rewrite-domaincom-to-wwwdomaincom-using-htaccess-in-apache/
In my project I have to make a subdomain, i.e
if the user name is XXX when he register, a sub domain will be created like XXX.example.com
how to do it?
I will use php for scripting.
I found a script that seems to do exactly that, create a subdomain on your server on demand.
It probably needs a little bit of tweaking for it to work on your particular control panel, but the review are quite positive as far as I can tell.
Link
Have you considered using htaccess and url rewriting?
Found this code that may help you:
# Rewrite <subdomain>.example.com/<path> to example.com/<subdomain>/<path>
#
# Skip rewrite if no hostname or if subdomain is www
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\. [NC]
# Extract (required) subdomain (%1), and first path element (%3), discard port number if present (%2)
RewriteCond %{HTTP_HOST}<>%{REQUEST_URI} ^([^.]+)\.example\.com(:80)?<>/([^/]*) [NC]
# Rewrite only when subdomain not equal to first path element (prevents mod_rewrite recursion)
RewriteCond %1<>%3 !^(.*)<>\1$ [NC]
# Rewrite to /subdomain/path
RewriteRule ^(.*) /%1/$1 [L]
Source (Post #6)
This might be a little more complex than you think.
I suggest to do some reading on mod rewriting and htaccess.
You could start here:
htaccess Tutorial
Modrewrite tutorial
Subdomain Modrewrite Example
EDIT: Or just go with one of the nice examples provided my fellow SO users. ;)
As long as this is for non-SSL sites, then by far the easiest way is not to bother - just use a wildcard DNS domain and vhost, then map any domain specific behaviours in your PHP code. If you need SSL sites then its a lot more complicated - you need to have a seperate IP address/port for each certificate - and woldcard certs can be very expensive.
If you're wanting to set up some sort of hosting package then its a bit more involved - how you go about this depends on what webserver and DNS server you are using.
Assuming (again no SSL) with Apache on Unix/POSIX/Linux and bind, then, again I'd go with a wildcard DNS entry, then:
1) create a base dir for the website, optionally populate this with a default set of files
2) add a vhost definition in its own file in /etc/httpd/conf.d named as XXX.conf
3) send a kill -HUP to the HTTPD process (causes it to read the new config files without having to do a full restart).
One thing to note is that you really shouldn't allow the httpd process direct write access to its own config files - you definitely don't want to give it root privileges. A safer solution would be to create a CLI script to perform this using the username as an argument then make it setuid and invoke it from the script run by the HTTPD process.
C.
the best way is to use a joker in your DNS server :
www.example.com. IN A 1.2.3.4
*.example.com. IN A 1.2.3.4
By this way, No subdomain has to be created : all are pointing to the same IP by default.
In your PHP code, you just have get $_SERVER["HOST"] and get the fist part :
$hostParts=explode('.',$_SERVER["HTTP_HOST"]);
$user=$hostParts[0]
First, you need to make sure you have a wildcard domain setup in DNS, and make sure your webserver (apache?) directs all queries for that wildcard domain to your php file.
Then in php you can look at $_SERVER["HTTP_HOST"] to see which subdomain is used for that particular request.
Since you will make sub-domains when an user registers.
Try this as .htaccess file:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^.htaccess$ - [f]
RewriteCond %{HTTP_HOST}!^www.domain.com
RewriteCond %{HTTP_HOST} ^([^.]+).domain.com
RewriteRule ^$(.*) /$1/%1 [L]
make a function of a controller which will take the value of sub-domain and display what necessary.
like::
public function show ($domain)
{
**.**..*..**.** Your code goes here
}
when a user will try this xxx.domain.com/controller/show this will be domain.com/controller/show/xxx . if you want to xxx.domain.com to be domain.com/controller/show/xxx just edit the htaccess file as you want.