trailing slashes, routing me to a different page in next.js - next.js

I am using nextjs to enable SSR in my application. Application structure is:
components -
component1.js
public -
img1.png
pages -
/order
[order].js
[country].js
contact-us.js
review.js
if I do 'localhost:3000/contact-us/' ,it routes me to [country].js.
I think when we do /contact-us/, it consider it as folder, but folder is not really there it takes first page that comes in that directory.
I have tried using exportTrailingSlashes: false in next config but it did not help.

I think the best way to avoid this would be to put your [country].js page in a /countries folder. That'll make your pages look like:
pages -
/order
[order].js
/country
[country].js
contact-us.js
review.js
Then you can get to the country endpoint via http://localhost:3000/country/[country].

Related

nested pages in strapi and nextjs

So we want to create a big website with nextjs and strapi.
We sometimes have deep nested pages like
www.ourwebsite.com/onderwijs/bijbelscholen/parttime-bijbelscholen
How is this possible?
I have tried to setup dynamic routing in nextjs which is working fine, but I have a problem.
If I want dynamic routes which are all nested I need to do something like this:
I know it's ugly, I'm sorry.
so now when I go to
www.ourwebsite.com/onderwijs/bijbelscholen/parttime-bijbelscholen
I just get the latest word from the URL and take that and put that into my API to get the right data which is working fine! I configured strapi so it finds by slug and not by id. So my API URL looks like this: www.myStrapiInstalation/api/pages/parttime-bijbelschool
but when I go to
www.ourwebsite.com/onderwijs/parttime-bijbelscholen
It's also working! but that's not good! Because it needed to give me a 404 page because it doesn't exist but now it just takes the latest word and gets the data from strapi. My API URL is still this of course: www.myStrapiInstalation/api/pages/parttime-bijbelschool
So what do I need to do?
Is it just not possible to make everything hardcoded and do I need to make nested folders with real names like: 'onderwijs', 'activiteiten' etc.
Or can I make everything dynamic so that people can make nested routes in nested routes in strapi?
I feel like this is a very stupid question, but I'm really stuck here.
Next JS allows catch-all routes, which is useful for nesting pages and have this format:
pages/post/[...slug].js
In your example, the pages folder structure would be:
pages/secondNest/[...page].js
However, since you're using Strapi to fetch the content, the routes of these pages should be known in advance so that if the user navigates to an invalid page, the result should be 404.
You can set the valid routes in Next with getStaticPaths. But notice that you will also need to set up a custom controller in your Strapi application to return the content tree of your website the way that getStaticPaths expects.
That way, it's ok to use the last part of the URL to get the content.
One disavantage of using catch-all routes, though, is that you must know the base of each URL. For example, if you have the following URLs
www.example.com/onderwijs/bijbelscholen/parttime-bijbelscholen
www.example.com/activiteiten/bijbelscholen/parttime-bijbelscholen
the folder structure in pages would be:
pages/onderwijs/[...page].js
pages/activiteiten/[...page].js
The key factor here is that the paths following the base of the URL should be set statically with the help of a custom controller that returns the tree of the content.

Rebuilt My .ASPX Website But How to Easily Redirect to .NET Core Pages [on Shared Hosting]?

I know this has been asked before but I haven't seen any simple explanations and I should also add I'm on shared hosting (Plesk). I don't see the URLRewriter utility installed on the server.
Anyway, I rebuilt my 2013 website that did use ASP.NET web forms (with .ASPX extensions). I'd like to be able to redirect my old pages to their new equivalents. i.e.
https://www.findaforum.net/diyfishkeepers-com.aspx
Should now point to:
https://www.findaforum.net/Forums/diyfishkeepers-com/
At the moment the .ASPX pages show this in a red box on a yellow screen:
XML Parsing Error: no element found
Location: https://www.findaforum.net/diyfishkeepers-com.aspx
Line Number 1, Column 1:
Where does this "come" from?
Incidentally, I'm looking for a quick and easy fix because I don't have too many external links pointing to my site's subpages, but it would be nicer for the user experience to fix it while Google works out I've changed my entire site.
This answer basically works:
How to redirect .ASPX pages to .NET Core Razor page
There's a good link to the URL rewriting regular expressions here: https://isitoktocode.com/post/introduction-to-url-rewriting-using-iis-url-rewrite-module-and-regular-expressions
This is what I've put in Startup.cs:
var options = new RewriteOptions()
.AddRedirect(#"ShowCategories.aspx", "/Home/Categories/")
.AddRedirect(#"Statistics.aspx", "/Home/TopForums/")
.AddRedirect(#"SubmitForum.aspx", "/Home/Submit/")
.AddRedirect(#"Help.aspx", "/Home/HelpAndFAQ/")
.AddRedirect(#"([0-9a-z-A-Z]+)(.aspx)", "/Forums/$1/");
app.UseRewriter(options);
Note: Make sure you put the specific ones at the top, then the generic ones at the bottom.
I also had some URLs like https://www.findaforum.net/lpsg-com where 'lpsg-com' is a forum name. I added a URL to the home controller to take care of these...
[HttpGet]
[Route("{code}")]
public ActionResult Unknown(string code)
{
return RedirectToAction(code, "Forums");
}

IIS with VBNet Aspx, how to setup/config a site (programmatically or not) to have a folder

I have IIS, using Aspx with VBNet.
I have a site ex. mystockmarketeg.com
I have many pages of the assets of the market, e.g. I use the ? and cod=THEASSET to change the page I want to display e.g.:
mystockmarketeg.com?myinsidepage.aspx?cod=ASSET1
mystockmarketeg.com?myinsidepage.aspx?cod=ASSET2
mystockmarketeg.com?myinsidepage.aspx?cod=ASSET3
Just changing the cod parameter I can access different pages.
But I think this doesn't perform very well on google.
So I want to have a url like this:
mystockmarketeg.com/ASSET1
mystockmarketeg.com/ASSET2
mystockmarketeg.com/ASSET3
Is there a way programatically in ASPX VBNEt or changing some property on ISS to do it without the need to create folders and putting the index page on each folder?
Configure ASP.NET Routing to achieve this result. Note that if you have hyperlinks with dynamic URLs, the URLs should be generated using <%$RouteUrl:...parameters...%>.
See also a detailed ASP.NET Routing description.

How to link images and pages in wordpress pages?

So, in the WordPress page, I need to link the pdf in wp-contents so I linked it with the relative URL as href="/wp-content/uploads/2017/03/test.pdf"
when I click it since my root in localhost is localhost/test it takes me to localhost/wp-content/uploads/2017/03/test.pdf (which doesn't serve the file). However, I don't think it'll be an issue in the server. Still, I want to know if this is the correct way?
Also, so I'm in page localhost/test/page22 Now on the page, I have an anchor tag as href="/page23" it takes me to page23 correctly, but when I'm in a different sub page say localhost/test/page/page2 now, the link takes me to localhost/test/page/page23 which is not correct as it should be localhost/test/page23. How can I solve these issues
WordPress provides functions for getting the URL of resources you should use these instead of having your code generate the URL. In this case you should call wp_get_attachment_url().

Meteor: Static HTML page as root

I made a meteor app, added a /public directory full of .html, .jpeg, etc...
It all works nicely just like that except that going to my domain's root doesn't show anything; I have to type in /index.html.
How can I make my domain root go to public/index.html?
Meteor wasn't really made with serving static content (in the form of HTML) in mind. The public folder is really used to serve things like the favicon and maybe an image here or there (http://docs.meteor.com/#structuringyourapp).
While you could technically do something like:
if (Meteor.isClient) {
window.location = 'index.html';
}
It's not really how it's supposed to work. And this brings other problems, such as making sure this only works on the / route.
A far better solution is to have nginx stand in front of a running instance of Meteor and serve static content directly.
It all really depends on why you're attempting to serve index.html like that. If it's for SEO purposes, just use normal Meteor templates (and routing) and use the spiderable (http://docs.meteor.com/#spiderable) package.
What Dino suggests is definitely true, but from your description ("my domain root doesn't show anything") it sounds like you might just want to put your index.html into your client folder and edit it to accommodate the way meteor likes it, namely removing all doctype declarations and the html tags. Afterwards you should be seeing something when you go to your domain root.
If you want to serve several different .html files, you could check out the iron-router, which allows you to do server side routing.
It's not standard practice to use mywebsite.com/public/index.html.
One reason is your site won't render the index page without navigating to mywebsite.com/public.
But if you really want to do this, simply add a public folder within your public folder.
public/public/index.html
It sounds like for what you're trying to do you'll want to put the index.html file into the form of a meteor template and then define that template as the one to be used for the '/' route in your routes file.
For example your template would look like:
<tementer code hereplate name="home">
<h1>My Home Page</h1>
</template>
And in your router file:
Router.route('/', function() {
this.render('home');
this.layout('homeLayout');
});
This is assuming that you're using Iron Router and have a separate template file that you're using for the layout. If you need a further example let me know and I'll be happy to help.

Resources