Problematic slashes at my URLs - apache

I've got a web page with URLs like http://www.domain.com/section.whatever.php. Problem is, whenever an URL like http://www.domain.com/section.whatever.php/something, the page still works but the slash completely destroys the design of the web, I suppose it makes the browser think all the static assets like images and CSS are at the wrong directory level.
Is there any way to avoid this?

One way is to update all your links to static resources so that they are absolute (from the root of the domain). For example: /stylesheets/screen.css

Related

Intrasite links breaking with S3 redirect

I've got a static website setup with S3 and CloudFront. When I navigate to a subfolder like example.com/nonexistant/, my example.com/index.html page loads (as I want it to), however it's text only and all of my intrasite links get messed up.
For example, my logo is located at example.com/img/logo.png. When I navigate to example.com/nonexistant/, the html for example.com/index.html loads, however it now looks for my logo at example.com/nonexistant/img/logo.png.
So links like <img src="img/logo.png"> are breaking because it is starting the search for the file from the wrong directory.
Is there a solution where I can fix something in my Redirection rules to have all pages ending in / redirect to example.com? I know I could probably just go edit my code to have all paths just appear as <img src="https://www.example.com/img/logo.png">, but I'm wondering if there is an easier fix here.
EDIT: I've already set up in CloudFront to have 404s go to /index.html with status code 200, and have in S3 set up my error document as index.html
Change your links to absolute paths, without the hostname.
<img src="/img/logo.png">
S3 redirect rules can only match the key prefix -- the left-anchored part of the string, so they can't be used to address this.
You could also use a Lambda#Edge function in an origin response trigger, if you really wanted to redirect 404 responses for paths ending in / back to the main page, but a redirect rewrites the path in the address bar (by definition -- otherwise, it is not a "redirect"), and I assume since you are doing the 404-to-200 transformation then you are probably doing something like an SPA where you need the path to remain the same, despite index.html being displayed.

Mask entire Vue.js app and it's subdirectories to another pages subdirectory

I would really appreciate some input in how to solve a masking / subdirectory issue with a SSR. It's also my first freelance gig as a front end developer.
I've built a Vue.js-app with dynamic routes, that is loaded in a Wordpress-page subdirectory.
www.wordpresspage.com/vue-app
Since I preferably want static pages (for SEO and meta tags) I'd like to host it on for example Netlify and generate static pages through ex. Nuxt.js.
Is there a way for me to mask the url so that it also routes the subdirectories?
So that my-page.netlify.com/sub-page can be accessed on www.wordpresspage.com/vue-app/sub-page
The alternative for me is at the moment to run the Vue app as SPA and forget about SEO and Open Graph etc.
OR get node.js running on the Wordpress site and do SSR, but honestly that sounds doesn't sound like it's worth the trouble.
Thanks for your input!
John

Specifying base URL with mod_pagespeed?

I've installed mod_pagespeed and I'm trying to figure out if this is possible to do.
Example URL:
<script src="/assets/build/js/test.js"></script>
The above URL is rewritten to this:
<script src="/assets/build/js/test.js.pagespeed.jm.QCz72nUS30.js"></script>
What I would like to do is for the URLs to be rewritten to the base of the website or to a folder that I specific. For example, I would prefer the rewritten URL to appear like this:
<script src="/test.js.pagespeed.jm.QCz72nUS30.js"></script>
Or something like this:
<script src="/sample-folder/test.js.pagespeed.jm.QCz72nUS30.js"></script>
Is this something that's possible to configure with mod_pagespeed? I want to do this for all images, javascript, and CSS files. Thanks in advance for any help you may be able to provide!
No, this isn't possible with mod_pagespeed. Here are the only URL rewrite control options available to you:
https://developers.google.com/speed/pagespeed/module/restricting_urls
You can rewrite the URL's with Apache's mod_rewrite. However, note the following limitations when doing so:
https://code.google.com/p/modpagespeed/issues/detail?id=676
This isn't possible, because at least as described it wouldn't work. Let's say on your site you have two different files called test.js:
/assets/build/js/test.js
/testing/test.js
And imagine you could tell PageSpeed to put everything at your webserver root:
/test.js.pagespeed.jm.QCz72nUS30.js
/test.js.pagespeed.jm.8U69T_7wiB.js
This would work as long as these resources stayed in PageSpeed's cache: it could use the hash portion of the url to look into its cache and find what resource the user wants. But what happens when the cache gets full and something gets evicted? Then a request comes in for one of these, it's not in the cache, and PageSpeed doesn't have enough information available to reconstruct the original url so it can regenerate it. PageSpeed would have to 404 the request, which would break the page.

Set Base URL using .htaccess

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

How to manage sub-domains on winhost with URL Rewrite and ASP.NET Optimization's bundles

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