-2

I currently have a simple website, hosted on github pages with a file structured in hierarchical directories as shown below:

/foobar.com
 /css
 /js
 /images
 /html
      /news
           /news_content
                fizz.html
                buzz.html
           news.html
       about.html
       contact.html
 index.html

However, when I am on the buzz webpage for example, this has resulted in the URL to become:

https://foobar.com/html/news/news_content/buzz.html

Is there a way to change this URL so that it doesn't show all the folder directories and instead, just the file itself i.e. https://foobar.com/buzz.html as I don't want to separate all the individual HTML files into separate folders?

3
  • This is not really programing question, but system administration: change the rules of apache/nginx Commented Feb 9, 2023 at 19:29
  • Im currently hosting a simple website on github so I'm not sure if I can change the rules of apache/nginx? Commented Feb 9, 2023 at 20:18
  • It would have been interesting to know this from the beginning. Commented Feb 9, 2023 at 20:20

2 Answers 2

0

Yes, you can change the URL to be more user-friendly by using server-side URL rewriting or client-side JavaScript.

For server-side URL rewriting, you'll need to use a web server such as Apache or Nginx and configure it to rewrite the URLs. You can find more information on how to do this for Apache or Nginx by searching for "URL rewriting" on their websites or forums.

For client-side URL rewriting, you can use JavaScript to manipulate the URL shown in the browser's address bar. However, this method may not be ideal for search engines or users who have JavaScript disabled.

If you are using GitHub Pages to host your website, you might be able to achieve URL rewriting by using Jekyll. Jekyll is a static site generator that supports URL rewriting and can be used in combination with GitHub Pages to host your website. You can find more information on how to do this by searching for "Jekyll URL rewriting."

Sign up to request clarification or add additional context in comments.

Comments

0

How a URL is resolved to a resource depends on the HTTP server and/or the server side programming language you are using.

Github Pages provides no features that allow anything other than a direct reflection of the directory layout in the URL.

The closest you could come would be to write a program that transformed the input (the file structure you want to work with) into the file structure that Github Pages will express as the URLs you desire (and then run it as a build step that takes the pages out of your working branch and into your gh-pages branch; possibly you could use actions to do this).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.