Domain Masking and Path Forwarding - php

I need to direct my domain www.abc.com to www.xyz.com/folder/form/ and pass parameters to the form, but I need to mask the path so that when users go to www.xyz.com that's all they see along with any passed parameters in the url. Is the possible? How can I achieve this?
I do not own both domains. I own www.abc.com and the folder in www.xyz.com, but not the naked domain. The domains are on different servers.
I have tried the solution setting the DNS to *.abc.com and the CNAME to www and www.xyz.com. But, CNAME's do not allow pointing to a path. If I do a 301 or 302 forward the domain is not masked. What else can I do. I've been pouring over this for days.

Few ways to achieve url masking without using DNS setting.
On server level: Setting up reverse proxy.
If you are using apache, you can use the module named mod_proxy.
Once you have enabled the module, Add following to your .htaccess which is in your abc domain root.
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://www.example.com/folder/form/
ProxyPassReverse / http://www.example.com/folder/form/
Another way to achieve similar result would be, as follows which does pretty much same thing under the hood.
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?abc\.com$ [NC]
RewriteRule ^ http://www.example.com/folder/form/%{REQUEST_URI} [L,P]
On language level: Using a scripting language like php and then pipe the data to and fro via. the second domain using curl. Kinda mix of 'man in the middle attack" and "phishing". But most importantly, it's pretty much possible.
Then we have other run of the mill solutions like using <iframe>. etc.

Related

How to manage multiple cities in classified site?

I am working on classified site. I am using PHP and MySql for that.
On my site when user select their city that time i want to change website url like in subdomain style. foreg:-
http://cityname.mywebsitename.com
Only one thing in my mind to implement this is creating sub domains for all cities. But it would be more difficult to manage when your cities goes 50+. You can't upload again and again same script for multiple domains. I think this is not a good idea to do this. I want to use a single script for that so i can manage it in simple way.
If you have any idea than please share..
Thanks in advance
I say you how i made it:
in DNS add wildcard subdomain record
*.domain.tld. IN A 1.2.3.4
add wildcard virtualhost
<VirtualHost 1.2.3.4>
DocumentRoot /var/www/vhosts/wildcard
ServerAlias *.domain.tld.
ServerName domain.tld
...
</VirtualHost >
create a .htaccess that redirect all requests to a FrontController (usually index.php)
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
parse $_SERVER['HTTP_HOST'] from php to obtain city name and play with your new FrontController (usually index.php)
i've done it on dedicated server or VPS with linux and plesk. With some modifications on the previous basis points, it is possible everywhere;)
You can't upload again and again same script for multiple domains.
You wouldn't need to. A single web-server can support multiple domains, and files can be shared between them. See, for example, Apache's examples of setting up "virtual hosts".
Just setup a DNS wildcard so that they all go to the same site. Then using PHP you can figure out what subdomain is currently being used. Also just make sure that they all use a SESSION or COOKIE based on the domain not the subdomain if you want information to be accessible between them all.
You will also need to setup apache to accept the wildcard. So that all subdomains get directed to the same code.
$urlParts = explode('.', $_SERVER['HTTP_HOST']);
$subdomain = $urlParts[0];
Don't go the path of using Apache Virtual Hosts... While you could store scripts in a common folder and access them all via PHP (include('../common_scripts/file.php') you still have to manage the vhost configuration. Better to set up a DNS wildcard and then have a single site which takes into account the current URL when running queries.

How to mask URL address?

Think I have domain.com that redirects into some.otherdomain.com.
I don't want to show exact url some.otherdomain.com to my sites visitors.
I need to mask my URL, so that it will look like domain.com
Any possible way? .htaccess / javascript?
The best way to hide your domain is to use a reverse proxy (apache, nginx, ...) and provide rewrite rules to it.
Assuming domain.com and some.otherdomain.com are on two physically different servers, and you can't change the DNS information for any of them, you'll need to install a reverse proxy on domain.com. You can use mod_proxy for this. The docs are at:
http://httpd.apache.org/docs/2.0/mod/mod_proxy.html
The following information is what you need to pay attention to:
A reverse proxy, by contrast, appears to the client just like an
ordinary web server. No special configuration on the client is
necessary. The client makes ordinary requests for content in the
name-space of the reverse proxy. The reverse proxy then decides where
to send those requests, and returns the content as if it was itself
the origin.
There's an example of a reserve proxy in the docs, but you'll want something like this:
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://some.otherdomain.com/
ProxyPassReverse / http://some.otherdomain.com/
Basically, any request that domains in will be proxied over to some.otherdomain.com - The local web server will forward the request over, buffer the data from otherdomain.com, then write the same data back out as if it were local data. Hope this helps!
I always think the best way is doing such things via mod_rewrite (or similar) in the server configuration (Apache or whatever is used)
On the Apache webserver of domain.com you have to enable:
mod_proxy
mod_rewrite
.htaccess
Once these requirements are completed then put this code in your .htaccess under DOCUMENT_ROOT of domain.com:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^ http://some.otherdomain.com%{REQUEST_URI} [L,P]
Important flag here is P (Proxy) which will basically make domain.com proxy all the requests to some.otherdomain.com without showing it in the browser. See here for more documentation on this flag: http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewriterule
The easier way would be to set up a page on domain.com with an iframe on it and set the source of the iframe to some.otherdomain.com. However, a user will be able to view source of the page and see that your iframe is pointing to some.otherdomain.com.
<iframe src="http://some.otherdomain.com/">...
The other option is to use a mod_rewrite in your .htaccess as shown in this thread.

Multiple domains for site subsections

Here's the deal. Basically I've got multiple domains, and I would like one of the domains to point to the regular base of the site, but the other domains to point to a subsection of the site without modifying the url in the address bar. The idea is that each of the extra domains are branded for their section.
Example:
www.domain.com Top level of site
www.domain2.com points to www.domain.com/abc
www.domain3.com points to www.domain.com/def
etc.
Also note that in the example 'abc' and 'def' are not real directories on the filesystem, but are virtual areas defined in a database.
I've spent quite a bit of time looking around and couldn't find anything that fits this. I do not want to use domain cloaking because it uses frames. Regular redirects obviously are easy to point to the right thing, but they change the url in the address bar.
Is there any way to accomplish this?
Edit:
I've added the alias as Mark suggested below, but can anyone shed light on how I could then use mod_rewrite to make this work?
First, your DNS records need to point to the IP of the web server.
Second, you have to set up Apache to serve multiple domains from the same VirtualHost. Enable mod_alias and then use the ServerAlias directive in your VirtualHost definition. For example:
ServerName www.domain.com
ServerAlias domain.com www.domain2.com domain2.com www.domain3.com domain3.com
If you've done that correctly, you should see the exact same content at each domain, without any redirection.
What you do next is an architectural decision. You can use mod_rewrite to hard-code URL routing rules based on domain, or you can use PHP to do the routing, based on the value of $_SERVER['HTTP_HOST'].
A mod_rewrite solution might involve adding something like this to your .htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} domain2\.com$
RewriteRule ^(.*)$ /abc/$1 [L]
RewriteCond %{HTTP_HOST} domain3\.com$
RewriteRule ^(.*)$ /def/$1 [L]
This is a high-level overview. Please comment on my answer if you need details on a particular part of the process.

How to build a subdomain from script

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.

URL Aliasing using .htaccess

I have a directory 'Domainname1/folder/'. In Domainname1, I have a sub-directory which is a sub-domain (abc.mydomain.com) of another domain. This is a reference to 'domainname1/folder/'. The thing is I want the URL links accessing 'domainname1/folder/' to display the sub-domain definition. So instead of seeing:
'domainname1/folder/'
They see:
'abc.mydomain.com/path'
How can I do this?
you should use a reverse proxy to do such setup, here a basic howto.
Hope this would help you
You can use the proxying abilities of mod_rewrite to achieve this. In the VirtualHost section for abc.mydomain, you can add:
RewriteRule (.*) http://mydomain/folder/$1 [P]
ProxyPassReverse / http://mydomain/folder

Categories