URL redirect to dynamic subdomain - php

I currently have a website (ab.example.com), where 'example.com' is the company's root domain. and 'ab' is a product's subdomain(website). Within the website (ab.example.com), I have multiple sub-products (gala, granny smith, fuji).
When a customer goes to ab.example.com/apples/gala I want them to be redirected as gala.example.com/apples. Similarly for any other sub-products I have. I understand that this is similar to .htaccess redirect to subdomain based on query string parameter, where .htaccess at the root folder is being used to add the redirect rules.
But does this mean that no changes have to be made in the cpanel or update dns entries for the new subdomains? I have also looked into the wildcard domain methood - Create subdomains on the fly with .htaccess (PHP).
I am confused about which method to use. I'm fairly new to php and its frameworks. The web application is in ,
php
Laravel
Azure
Apache
Linux(Ubuntu)

Related

Allow users to access their page on my site by using their own custom domain

I'm building a PHP MYSQL based site builder based on smarty templates where each site would have a folder which would contain all the site files such as html, assets and scripts. I want to add a option for my users to add their domain name in the backend for each site, point a dns record to my server and be able to access their folder on the server via their domain name
For example their url on my site would be www.sitebuilder.com/sites/example/
Their domain: www.exampledomain.com
When someone visits this domain, the index.html at the url would be shown.
I hope this makes sense, How do i achieve this? Thanks!

Dedicated domain for admin backend

I have Symfony2.8 application installed on my server. To make things easier, let's assume that in /very-long-path/web directory. I also have domain for this directory - eg. example.com. Page at example.com is accessible by all my users. Application has also backend for admins at example.com/admin. I think this is common configuration for many webpages.
What I want to do is:
Buy second domain eg. admin-of-example.com.
Disable access to the example.com/admin (or configure redirect to admin-of-example.com)
Make backend for admins accessible only via this second domain.
Is it possible and how? I completely don't know how to do that? Probably mod_rewrite?
What may be important? Symfony base on fron controller, therefore example.com/admin not directs to real folder - there is no /very-long-path/web/admin directory. Frontend for users and backend for admins are parts of one application, therefore I cannot move backend to other hosting/domain physically.
You can restrict routes to be matched only when the request is for a particular hostname: http://symfony.com/doc/current/routing/hostname_pattern.html

Route/create a sub-domain in CakePHP, how to

I've tried solutions as such, but they don't see to address the problem Im at.
How to create a sub-domain in CakePHP?
I have a CakePHP app in publichtml/lastroarte.com running ok. I went to my DNS and created for a subdomain entries for sandbox.lastroarte.com a test subdomain for the new version of my which we'll be upload the new app.
If I browse to the subdomain now, it redirects me the home page of my domain, still displaying the url sandbox.lastroarte. I've found entries for the pages in the Routes file of Cake, although I have not found way to say a subdomain should display the index of its own folder (public_html/sandbox.lastroarte.com). Am I doing the right approach? How to achieve this?
Appreciate your answers.
(Assuming you are running apache as your web server)
You have created a sub-domain, but have you created sites-available and sites-enabled files and restarted apache?
If you are using your host's control panel it will do this for you, but you will need to associate your public_html/sandbox.lastroarte.com directory to the sandbox.lastroarte.com sub-domain.
In short this doesn't sound like a Cake routing problem, it sounds like apache is routing traffic from sandbox.lastroarte.com to lastroarte.com.

How to automatically parse a subdomain with WordPress

We have a unique Wordpress installation and the front page is an iframe that needs to redirect to an address which depends on the URL it's being accessed from (more specifically, it depends on the subdomain).
Let's say, if the address is :
<subdomain>.<Domain>
then the iframe should redirect to:
<subdomain>.<OtherDomain>
ex:
chc.mynewdomain.com
should contains an iframe redirecting to:
chc.myolddomain.com
The questions are:
1- how to have all subdomains go to that unique wordpress install?
2- how to parse the subdomain in the underlying Wordpress (PHP) code, possibly check against a white list of subdomains, and build up dynamically the iframe URL?
To have all subdomains go to the same wordpress install:
first, setup a wildcard domain entry. procedure varies depending on the dns host
then setup a wild card entry in your httpd config (typically involves adding a * in hostname)
As for handling it in wordpress, depends what you are trying to do. The most likely scenario is you want a different page for every subdomain so you will have to enable wordpress multi site for multiple site. Then, you will have to install the domain mapping plugin. A url that describes that is here: http://wp.tutsplus.com/tutorials/wordpress-multisite-beyond-basics-essentials-and-domain-mapping/

Building a SaaS application on Zend Framework

I am on the way of building a SaaS application using Zend Framework on PHP. Here is the basic information of the project. Its Project Management System on SaaS model. When the user registered on the site, they will get a domain name like the format:
user_name.pms.com
user_name - The chosen User Name when the user registered on the Project Management System (pms)
pms.com - is the main SaaS Server.
Currently we provide the Sub Domain on our Server. And for big firms, it won't look good and they may prefer to get their own domain instead of this default one. So there may be:
user_name.pms.com [Always Present]
user1.com [ The custom or independent domain of the User ] This custom domain needs to link into the default user url.
The full website is planning to develop using Zend Framework.
On Zend Framework, we are having following HTAccess on the root folder for its working and is below:
SetEnv APPLICATION_ENV development
RewriteEngine On
RewriteRule .* index.php
Here are my questions:
Do I really need to create Sub Domain like profile url for all users once they registered on the site ?
If it need to create Sub Domains, can PHP check whether the chosen sub domains exists or not and can create Sub Domains from the Script itself ?
If there is no need to Sub Domain, can we achieve the same goal using HTAccess in Zend Installation ?
Can you provide the HT Access code which does the following:
"user_name1.pms.com" need to redirect to "pms.com"
"user_name1.pms.com/contact" need to redirect to "pms.com/contact"
ie any request on the Sub Domain like URL must redirect to main website with the format: pms.com followed by Query String.
Very Important:
Important 1:
When I said the redirect to main website, I need to keep the sub domain like URL on the address bar but the request will be served by main website.
ie "user_name1.pms/contact" is going to be served from pms.com/contact but on address bar we still see the url "user_name1.pms/contact"
Important 2:
Whenever we uses the HTAccess to redirect the request to main Zend Server, can I identify the actual url entered on the address bar ie "site1.pms or site1.com" ?
Another Question of Custom Domain Redirection:
The custom domain name like "site1.com" or "site2.com" need to redirect to either:
Option (a): "pms.com"
Option (b): "site1.pms.com
to serve the request. Here also, I need to keep the url on address bar same like the one user entered.
Which above option is better (a) or (b) ?
Which technology does this work, domain mapping or CName ? Or Any other technology for make this working.
There are several ways to get you at least near to what you want... but to get all of the way there, you're going to need to get a little more depth.
First of all, your questions:
You may need to actually set up a whole virtual host for each user, if you intend for them to be able to interact with your site through their own domain. If you just want them to have their domain redirect to yours that can be done at their registrar (and if they can successfully use masking, which I've always found problematic, it may work completely without doing this. If you ignore the custom domain requirement, then you can manage subdomains completely through mod_rewrite without having to actually set them up.
Probably the best architecture for your site is to proactively set up whatever needs to be set up the moment that the user signs up. Don't try to do it "just in time" when the user first tries to access it, and therefore it's just as simple as displaying an error when someone, say, types in usre.pms.com rather than user.pms.com.
You can use htaccess, or the config file for your site (which is better for performance, but just strictly for "getting done" purposes, htaccess will work fine).
Google
Very Important Point #1: this is how mod_rewrite works. No worries.
Very Important Point #2: yes, so long as you include that information to be passed along in your mod_rewrite rule
Your Last Question of Custom Domain Redirection:
This is where things get complicated. You can't serve site1.com from pms.com without apache being fully aware that it's looking for site1.com (unless you get forwarding with masking to work without issue at the registrar). Generally speaking, if you're using forwarding of some sort, then you'll want them to forward to the subdomain, and all will be good completely through mod_rewrite. If they are directing the domain straight at your server, a CNAME record is probably the right choice, directing to the subdomain, but you'll still have to learn about virtual hosts and how to properly set it up to get everything to work.
I think you may be signing on for more than you realize by letting your clients have their own custom domain. You can learn how to do what you want with subdomains probably in an afternoon or a couple days tops. Figuring all of the ins and outs to working with custom domain names could take a lot longer.
The sub domains can be handled using some technique in CPanel. To add vurtual sub domains from CPanel, do the steps:
Select "CPanel - Sub Domains"
Enter star and choose your domain name
Choose the directory to which you need to redirect
And handle the redirection from your page.
To develop a SaaS application using Zend, check the tutorial SaaS application development using PHP in Zend Framework

Categories