how i can fix url redirection in netlify hosted site? - netlify

i have hosted a react site on netlify but redirect is not working as i want.
You see that here: https://unsplash-app.netlify.com/photo/C6-GjBAOtZc
for example if i go to /photo/h478dhek first time it load when i redirect from netlify site itself but, when i refresh page it just not work and say page not found. what should i do to make redirection work i want it to be.
i have tried creating _redirects file in my build directory but in official documentation it's not clear that redirection will work in refresh the page

Since this is a single page (React) app, have you tried a rewrite rule:
_redirects
/* /index.html 200
As you mentioned, this file would need to be in your build (deploy) directory after the build.

Related

Why Netlify redirects "/index" to "/" when "index.html" exists (no custom rules defined)

We host our website with Netlify. We have no redirect rules set on our side.
When accessing a url which ends in "index" (for example "animals.com/cats/index") (assuming there is the real index.html page there) Netlify will do a 301 redirect, retrieve index.html, and set the url to the root "animals.com/cats/".
This behaviour is also possible to see in Netlify docs
Open "https://docs.netlify.com/routing/headers/index" -> in will redirect to "https://docs.netlify.com/routing/headers/".
Where is this behaviour specified? I can't find anything in their docs.
I contacted Netlify support and they explained how it works.
There is an option in "Asset optimization" which is when set to "Enable" allows to enable "Pretty URLs".
With pretty urls there is redirection happening automatically.

301 Redirections in a bundled react project that does not require Javascript, using firebase hosting

I'm currently building a URL shortener and am using React for its frontend. It is where my domain (let's say example.com) is linked to using Firebase Hosting.
I'm in a bit of a struggle trying to figure out the redirection part of the service, as I want this redirection to be "HTTP native"; it should not require JS to redirect, just a plain 301 redirection.
Shortened URLs look like this: example.com/go/:linkId.
When a user clicks on a shortened link, My server should get the request, find out what URL is linked to the shortened URL's id, and redirect to the original.
Since I don't want to involve JS, I tried to use the redirects setting in firebase.json. At first, it looked promising just to use:
"redirects": [
{
"source": "/go/:linkId",
"destination": "<SERVER_URL>/go/:linkId"
}
]
Two issues with this approach:
It won't work on localhost, as (AFAIK) firebase.json isn't being taken into consideration when running Webpack dev server.
Anyway, there is a different server URL for development and production environments. I don't want to hard-code the URL since it won't let me separate between them.
I was thinking about redirecting to a go.js file or something that will live in the dist folder with index.html, but It won't be resolved a node.js file.
If you have any idea how to solve this, I'd be glad to hear.
Thanks!
Redirects will work locally when you use the Firebase CLI, i.e. by running firebase serve. If you need to preprocess your source to get the final distribution, you do that locally, and then call firebase serve on the output of that preprocessing step.

React Subdomain Goes to Main Site 404

URLs on my subdomain like react.mysite.com/page1 go to mysite.com/404.html, when refreshed, instead of the appropriate React component.
Can i have a seperate .htaccess for my subdomain? If so what would I write in it so it would look at react.mysite.com and let that handle the rest of the url?
I'm relatively new to React and SPA, so any help would be greatly appreciated.
So you can have multiple .htaccess files.
And the rule is available in this question:
Apache web server doesn't allow me to refresh on /about but on localhost its working fine

How to STOP redirecting my website to mobile.mywebsite.com in smartphones

I have developed a website www.mywebsite.com and it is ready to go live.
I have used Codeigniter framework.
When I enter www.mywebsite.com from any android/iphone, it redirects automatically to mobile.mywebsite.com and displays page not found error. I dont have any mobile site developed for this. I want to show the main site even on the smartphones.
I am not good at .htaccess file, and I am using default .htaccess to remove the index.php in the url.
I tried creating a subdomain mobile.mywebsite.com and pointed to root path. But same response. I search online, but didnt find anything on how to STOP redirecting.
Thanks in advance.
When I was uploading my local files into the server I was NOT overwriting the old ones assuming the folder is clean and no need to overwrite. But my hosting provider has default .htaccess which is redirecting to the mobile site.
I deleted the old one and gave my .htaccess without the mobile redirection and everything is in place now

ServiceStack Rockstars - why does it not redirect to folder/ with IIS Express?

I'm trying out ServiceStack, and have cloned the RazorRockstars sample from Github.
If I open in Visual Studio 2012 and start RazorRockstars.WebHost project, it all runs fine in VS development server.
If I then change the project to use IIS Express 8, the URLs in the dead/alive menus no longer work correctly.
It turns out that the link in the menu points to directory name without a slash: http://localhost:2000/stars/alive/vedder, and when executed, the server will send back a 302 and redirect to http://localhost:2000/stars/alive/vedder/ (note the trailing slash), and after that all is well.
In IIS Express however, this redirect doesn't happen, and the url in the browser remains without a slash, which in turn breaks the page.
The interesting part, however, is that the default.cshtml page will execute from the directory, but the included partial content.md will not. It looks as if SS is aware this was a folder and will look correctly for default.cshtml, but then somehow fails to look for content.md partial.
Is this a bug with SS implementation or expected behavior? Presumably it would make sense for ServiceStack itself to return a 301 in this situation.
I just had the same issue.
I had to download the URL rewrite module for IIS. And create a rewrite rule in the web.config file in the RazorRockstars.WebHost project.
See this link for more detailed explaination. http://www.tugberkugurlu.com/archive/remove-trailing-slash-from-the-urls-of-your-asp-net-web-site-with-iis-7-url-rewrite-module

Resources