I have a setup in Laravel whereby I have different sections of the site powered by one codebase. A section is defined by the first slug of the uri:
localhost.dev/section1/feature
localhost.dev/section2/another/feature
However, I also have a domain alias/proxy for these so that each section can have its own independent branding and SEO without splitting up the codebase.
section1.dev/feature (alias of localhost.dev/section1/feature)
section2.dev/another/feature (alias of localhost.dev/section2/another/feature)
However, Symfony's HTTPFoundation appears to be too smart to be fooled by this proxy, and whenever you use URL::full() or URL::current(), the domain remains localhost.dev despite your browser telling you that you're on section1.dev or section2.dev
Is there a way to configure .htaccess differently, or is there a way to make Laravel's URL::full() or URL::current() mirror what's in your address bar?
First: a domain alias is not a proxy.
Second: the app.url config option gets used by the application to generate URLs. Try making it an empty string.
Related
There are two page trees in my TYPO3 and I link between them. Both websites use an SSL/TLS encryption for the frontend delivery and thus should only generate relative links (if on the same domain) or link to my second domain (which it does, but only using http and not https).
Now the reason for this seems clear: I've never told TYPO3 to only generate https links. The question is: how would I do that in the first place?
I've come accross the possibility to work with config.absRelPrefix but this doesn't work when linking across domains.
use
config.typolinkCheckRootline = 1
this way typolinks check if the target page belongs to the current domain.
https://docs.typo3.org/typo3cms/TyposcriptReference/Setup/Config/Index.html#typolinkcheckrootline
Apparently, config.typolinkCheckRootline = 1 as well as any combination of config.absRelPrefix and config.baseUrl won't help it, if TYPO3 get's the wrong HTTP host and only get's the host via HTTP_X_FORWARDED_HOST env var.
I am using Apache httpd and proxying requests to my Tomcat server where my application WARs are deployed.
Let's say I have application App and servlet URL pattern /servlet1 and domain name abc.com. So, when I forward request from my ROOT.war servlet to /App/servlet1, my URL changes to abc.com/App/servlet1, but I would prefer abc.com for a better user experience.
I know I could do this by re-nameing App to ROOT.war but that is not an option for me, as we already have a ROOT.war for another application.
Is it possible to rewrite abc.com/App/servlet1 to abc.com other then ROOT.war? If so, how do I do it?
The way to do this is to merge your ROOT and App applications together into a single application.
No servlet contains is going to be able to detect when some URLs should go to one application and others should go to another without some obvious mapping strategy. The servlet specification uses mandates the use of URL prefixes (context paths) to differentiate between deployed web applications: you cannot mix them together unless they are in fact the same application.
There are very very ugly ways to do this, but those techniques end up opening up a whole lot of headaches and continued hacks just to get around what sounds like a senseless requirement: making URLs pretty. Nobody cares how pretty a URL is. Make sure that example.com takes the user to the right place and don't worry about any of the rest of it.
I'm setting up a clients area so my customers can review their site during development. I want to set it up so the URL is http://clients.mydomain.com/clientname/
Is there a way in the .htaccess file to set that as the base URL? I'm using the leading / format for my URLs in the page (ie /about/ or /css/), which will is fine locally & when I deploy to production, but doesn't work in the scenario outlined above.
The proper way would be to use relative links in your HTML, it's unreliable to try to track the referer and rewrite every subsequent request to shove the /clientname/ back in as a prefix.
If you make a subdomain for each customer, and develop sites there, you don't have to change the base URL. This will prevent other htaccess rules to break also when deploying to the live server...
So use:
http://clientname.mydomain.com
I am using ASP.NET MVC4 with WinHost.
Just like the question asked here, I ran into the same issue:
I'm trying out WinHost and I'm running into some issues with
sub-domains. On WinHost, you can have multiple sub-domains per hosting
account, but each sub-domain points to the root website. E.g. you can
have www.example.com, sub1.example.com, and sub2.example.com but all
of them display the content at http://www.example.com/.
Other Hosts allow you to point sub-domains to a sub folder in your
website. This would allow you to point sub1.example.com to /sub1,
sub2.example.com to /sub2 and www.example.com to /.
WinHost recommends using an asp/aspx page to redirect
http://sub1.example.com to http://sub1.example.com/sub1, which points
to /sub1. While that would work, I'd like to not have the subdomain in
the url twice.
So I tried using IIS7 URL Rewrite to point http://sub1.example.com to
/sub1. Ben Powell describes this in detail on his blog.
I've managed to get this portion to work so that http://sub1.example.com actually points to my virtual application "/sub1" in IIS.
If I use Url.Content, it works flawlessly.
Now, I am using ASP.NET Optimization and I bundle scripts and css. Issue is that it absolutely require a relative url ie:
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.unobtrusive*",
"~/Scripts/jquery.validate*"));
However, because it's a relative url here is what I will get in the markup:
<script src="/sub1/bundles/jqueryval?v=UgyEMAYOuSB9Bb6HcOEVHpd6fIIp54yF086SRNVcdIY1"></script>
Of course, because of the "sub1" it doesn't find the file. I thought about URL Redirect that I never actually got to work. Maybe a route in MVC? Unsure how to do this as well. I could also drop the bundling alltogether to use "Url.Content" which I think is sad.
What would be the best way to handle this issue?
I know you can use IBundleTransform to modify contents in a bundle based on unique circumstances. You may be able to modify the bundle context itself. Here is a link MVC4 StyleBundle not resolving images
One of YSlow's measurables is to use cookie-free domains to serve static files.
"When the browser requests a static
image and sends cookies with the
request, the server ignores the
cookies. These cookies are unnecessary
network traffic. To workaround this
problem, make sure that static
components are requested with
cookie-free requests by creating a
subdomain and hosting them there." --
Yahoo YSlow
I interpret this to mean that I could experience performance gains if I move www.example.com/images to static.example.com/images.
Although this is easy to do, I would lose the handy ability within my content management system (Joomla/WordPress) to easily reference and link to these images.
Is it possible to use .htaccess to redirect all requests for a particular folder on www.example.com to a folder on static.example.com instead? Would this method also fool the CMS into thinking the images were located in the default locations on its own domain?
Is it possible to use .htaccess to redirect all requests
for a particular folder on www.example.com to a folder on
static.example.com instead?
Possible, but counter productive — the client would have to make an HTTP request, get the redirect response, then make another HTTP request.
This costs a lot more than the single line of cookie data saved!
Would this method also fool the CMS into thinking the images
were located in the default locations on its own domain?
No.
Although this is easy to do, I would
lose the handy ability within my
content management system
(Joomla/WordPress) to easily reference
and link to these images.
What you could try to do is create a plugin in Joomla that dinamically creates these references.
For example, you have a plugin that when you enter {dinamic_path path} in an article, it appends 'static.example.com/images' to the path provided. So, everytime you need to change the server path, you just change in the plugin. For the links that are already in the database, you can try to use phpMyAdmin to change them in this structure.
It still loses the WYSIWYG hability in TinyMCE, but is an alternative.
In theory you could create a virtual domain that points directly to the images folder, such as images.example.com. Then in your CMS (hopefully at the theme layer) you could replace any paths that point to the images folder with an absolute path to the subdomain.
The redirects would cause far more network traffic, and far more latency, than simply leaving things as they are.
It would redirect the request but the client would still be sending its cookies to the server, so really you accomplished nothing. You would have to directly access the files from a domain that isn't storing cookies for it to work.
What you really want to do is use staticexample.com/images instead of static.example.com/images so that you don't pick up any cookies on the example.com domain that you may have set. If all you do is server images from that domain with a simple apache server or something then you can configure that server not to return even a session cookie.
The redirects are a very bad idea. Cookies cause some performance hits but round trips to the server such as a redirect would cause are a much more serious performance issue.
I did below and gained success:
<FilesMatch "!\.(gif|jpe?g|png)$">
php_value session.cookie_domain example.com
</FilesMatch>
What it means is that if you do not set images in cookie information.
Then images are cookie-free with server.