URL with trailing slash does not load scripts and CSS in PHP site - apache

what is the difference between these two URLs:
abc.com/company-profile.php
abc.com/company-profile.php/
When I directly open the first one (without trailing slash) the page open perfectly.
But when search it in Google I get the second link (with trailing slash) and when I click on this link, the page only shows code, no script or css included.
After clicking on any style.css, the page shows like abc.com/company-profile.php/css/style.css.
What is happening?

The cause can be that Google indexes your website with a sitemap.xml file having the company-profile.php/ url and not company-profile.php.
And unfortunately your website doesn't manage well the trailing slash at the end of the url (you can fix this with updating .htaccess file)
You have to check the sitemap generated and downloaded by Google.
The url's sitemap name differs according you are using Wordpress, Drupal or another CMS, or a custom website...

Related

Cloudflare Pages .html redirect causes Redirection Error for Google indexing

It seems that if I have in my page links that use the .html extension, Google Search Console's crawling or live test will fail to retrieve those resources, with a Redirection Error message under Page resources: x/x couldn't be loaded, even though a client browser can get the results just fine.
Side note: If those .html URLs are tested directly for a live URL test, they show they can be retrieved and can be indexed.
Is there any solution to this besides removing all the .html path extensions in production? Keeping the extensions is for the local testing Python server.

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.

Website redirecting inproperly

I have the following issue, I'm building a website and it's deployed inside a subdirectory of my server, the website is a referral for sales services. Then on the homepage I have two links that references the two main categories of the products sold in it. Now the first link href's is /es/sports/ if I click on it I get a 404 error but if I copy paste the url in the browser then the page is shown correctly.
Note, when I click the link it is redirected to /sports/ instead of /es/sports/ as corresponds.
Maybe some htaccess configuration on the root of the public folder?
It's a laravel powered website.
The website url is the following. http://entrenamiento.com/es/ the links are the ones on the left sidebar.
First of all thanks for all comments and help. The thing is as follows, the parent website on the htaccess file has no support for trailing slashes after the URL. So once the trailing slash rule is enabled then the website works as expected. Thanks again

What are the risks of using 301?

We want to migrate from CMS to own system.
Page addresses in CMS and own system are different. We want to use 301 redirect to all website's pages.
The output HTML of CMS and own system have some few differences:
OpenGraph semantic
No javascript generated by CMS
Should we be afraid the failing of search traffic?
If done properly, the 301 is the way to go when the url is changed permanently. The most common mistake our clients do is to change the URL of a page and never redirects the old page's url to the updated location. This causes 404 pages.
My advice is to structure everything. Start with generating a file containing all current URL of the website. Then use an excel file or google sheet and pages those in. Right next to that column add another one - this is the column where you decide what you should do with each URL (either keep, remove/kill, combine it another page or change the URL).
Since you want to change the CMS, I am not sure how your have structured your pages right now and how they are indexed, BUT whatever you do, make sure that if anything in the URL has been changed, use a 301 to permanently redirect the old URL to the new location. Otherwise if that page receives some traffic, you will lose the traffic as the visitors would land on 404 (page not found) page.
Go through the URL list, one by one and determine what will happen with that page/url.

Redirecting Pages: Names to Standard Address

I have WordPress installed in the root of a website, and recently enabled a custom permalink structure just for the sake of having good looking page URLs (only pages are used in this website, no posts at all — it's not a blog). Unfortunately this is causing some problems with other parts of the website, outside WordPress.
So I'd like to go the manual way: and redirect URLs like /my-page to /?page_id=32 just for a selected amount of pages. Is it possible to do that using the .htaccess file? What would the rules look like?
If you're redirecting pages from Wordpress to other URLs, you can use .htaccess. But it's probably easier to use a plugin to redirect rather than edit .htaccess.
See WordPress › Redirection « WordPress Plugins to easily set up redirects and log redirects, errors, and more.