My client's application is temporarily running on my staging server (my-domain.com), while on his server (client-domain.com) I placed an .htaccess file to redirect all requests to my staging server. This works fine so far except when building URLs with Laravel's helper.
When I call {{ action( 'Controller#getIndex' }} for instance, Laravel returns my-domain.com/index (instead of the desired client-domain.com/index).
For now I solved this by replacing these calls with absolute, hard coded urls but that is disturbing my workflow.
So, is there a way to force Laravel to use a specific base url?
Laravel generate url for the current domain it is running on. Currently, laravel is running on my-domain.com even if you are calling it using client-domain.com.
That depend on how you are redirecting of course.
So, firstly why are you redirecting the client domain to your server.
If it's a permanent redirection, then it's better for you to:
consider it just as it is: a redirection
consider changing your architecture to support both domains equally (no redirection so)
If it's just for testing/debugging (or whatever) and this redirection will go away when you will move into production stage, you don't have to worry about that:
laravel is creating links to avoid doing the extra, useless redirection on each page load, in fact it's a good thing performance wise.
when you'll go into production an install the app directly in client-domain.com, laravel will make all links points to that location automaticly, so you'll be safe to remove your app on my-domain.com
On a side note, it's not really recommended to have the same content accessible with multiple urls. So, you have to 301 redirect one domain to the other (seems to be the current behavior) and then use only one of them.
Edit:
and to answer you last question, there is no way to set the base url in laravel (for now at least). There seems to be an issue on github about that (here: https://github.com/laravel/framework/issues/92 ). Maybe you can investigate in that direction, but I don't think it'll be implemented one day because that seems to be hacky and quite uncommon in any regular web application.
Related
I just finished writing a website using polymer 1.0+ with a PHP MVC framework on the server. I am about to start a new project, but I want to use app-router. Unfortunately to use app-router I have to redirect everything to index.html using my .htaccess file. But my PHP MVC wants everything to run through its index.php.
It got me thinking. Should I just write my PHP code as a REST API and have my Polymer code get data via iron-ajax?
If your PHP is mostly only used to access data, this sounds like a pretty sound idea in my opinion. It also opens you up to upgrading or migrating your backend to newer technology since it will only be a data layer.
You need to understand WHY app-router wants everything to route through index.html. The reason is that it invents other routes which are exposed to the browser that aren't real. Normally, as you are running the app, that doesn't matter, the browser doesn't attempt to load those url's, the app-router is just putting them into the history.
However, your use may take one of those urls and try and paste it (or get someone else to paste it - having sent it to them via (say) email) into the address bar, or you may have an <a href= link on your page and what you want to happen is the app loads from its base location and then the router routes it to the correct place.
So actually index.html isn't some magic incantation, its the url that the app is loaded from. If that happens to be index.php then that is what you should use.
i'm making multi language site that can be run from different hosts.
some hosts can only have one language.
i'm having trouble figuring out how to redirect users from one language to another
for example:
if site.com only has de languge (site.com/de)
and someone tries to go directly to site.com/en i want redirect them to site.com/de straight away.
or how to restrict locale prefix based on host(should be dynamic)?
i think there is a way to do that from service listener but i dont know what to pass to it to be able to redirect from it.
First of all I think that this kind of limitations should be provided by httpd server configuration. For me this is a place where you should allow/disallow access based on remote host IP, and then redirect to allowed namespace of the site.
Answering your question try to use JMSI18nRoutingBundle bundle, or similar. In this case you can overload Router/DefaultLocaleResolver.php class, replacing it in configuration (jms_i18n_routing.router.class).
In your overloaded router add host based resolving to resolveLocale function by checking $request->getClientIp();. This way not only mainpage will be redirected to "proper" locale but also any link in your application.
I think this is a cleanest way toy implement that.
Good Luck!
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
I have a web app of which I would like to create a mobile version with jQuery Mobile. The existing application is built in CodeIgniter; I'll be using the same controllers, models where I can; (especially models since I'll be needing the same data anyway, might have to write new controllers).
I'm a bit confused as to how to get started. I want to put my mobile version on a subdomain (m.myhost.tld), however.. since my app is at www.myhost.tld and I don't feel like copying it all over to another folder and maintain two, I'm a bit confused.
I know I can use the User Agent library in CodeIgniter to detect mobile browsers and load views accordingly; I just don't know how to get this working with a subdomain. Do I need to customize my app/config/routes.php file here, or can I fix this with some .htaccess magic? I have next to none experience with .htaccess though. The only thing I know is how to remove my index.php from CI apps, and that's a copypasta snippet.
EDIT: I wonder if I can use a tutorial like this one to do what I want to do? It seems to be doing more or less the same thing, just with dynamic usernames instead of a simple 'm.'
EDIT 2: Some more information, I guess.
Say I detect mobile browsers using the User Agent library included with CodeIgniter. I want to direct these browsers to m.myhost.tld. However, the content that I want to display on the mobile website comes from a controller called mobile which I can also access through www.myhost.tld/mobile/; so my question is if there is a way to route a URL like.. for example www.myhost.tld/mobile/about to m.myhost.tld/about. I'm not even sure if this is possible, teehee. Still learning!
I'll be grateful for any advice you can give me. Thanks a lot!
If you want to share the same files in different hosts, you must assign the document root folder of your sites in your web server, this is an explanation for static files, but is the base to you understand.
browser -> host:z.y.xxx[ip.ip.ip.ip] -> web server -> read filesystem : document root + browser request path
so if your document root is:
/hosting/http/z.y.xxx/htdocs
and the request is /path-to-static/index.html the server try to read:
/hosting/http/z.y.xxx/htdocs/path-to-static/index.html
In conclution, you create the new host m.mysite.tld in your web server and you change the document root as the same of the you www.mysite.tld also you could use directives of host alias, like Apache ServerAlias directive. Have lot of documentation to how you could configure a web server.
You could handle the host name in php with $_SERVER['HTTP_HOST'] variable.
If you could specify more, I could help more.
have a nice day
I have used the Apache Mod Rewrite for PHP but not in IIS.
BACKGROUND:
I have inherited over 400 sites on IIS with PHP all with a copy of the identical code base.
The current code base has a unique connection string per client and that is why it was copied over and over again.
Each being a subdomain pointing an individual site in IIS:
customer1.mysite.com
customer2.mysite.com
I have used Sessions and PHP to get to a single code base with each site pointing to its own directoy that contains a single PHP file that pulls variables from the database master table and places them into Session strings using a virtual directory for the now single code base.
But now I want to take it a step further. The idea for this came from using Zend bootstrap with Apache.
My next step is to eliminate the indiviual PHP files and use a bootstrap file along with a single code base in a single directory on a single IIS site. www.mysite.com
QUESTION
I want to know if it is possible to do a rewrite rule so that any subdomain on mysite.com goes to mysite.com/bootstrap.php thus customer1.mysite.com goes to www.mysite.com/bootstrap.php and customer2.mysite.com goes to www.mysite.com/bootstrap.php but the subdomain stays in tack - even though it is just one site.
So that a call to: customer1.mysite.com goes to www.mysite.com and the bootstrap can read the subdomain, look up the site parameters, place them in sessions, and then allow access to the site.
Or if you know of a better way to accomplish this please let me know but I cannot change the 400 plus subdomains the clients are using to access the product.
If you are using ISAPI Rewrite (A ModRewrite for IIS), you could have your bootstrap.php look at the "X-Rewrite-URL" HTTP header, which is the original, unmodified, URL, and make a decision on what to show based on that.
Rewrite would not work because the wildcard is not allowed. So I had to add each subdomain to a single folder. A little more work but it solved the problem.