Hiding page names in the browser - html

When we launch a website, we usually see webpage name (menu.php or admin.aspx) but I would like to hide that name and show only virtual path or just website name. I don't want it for the first page because I did that with default.aspx but I want to implement it for the whole website.
Showing www.abcd.com/faq/ instead of www.abcd.com/faq/faq.html
Note: My code is not MVC code and server is Apache.

Use .htaccess to rewrite the URL. Millions of tutorials are out there for that ;)

What you are asking is achieved using (for xampp, wamp, lamp or any other apache powered webserver setup) htaccess rewriterules. The rules take the URL and break it into parts that can be modified or used as variables to feed other pages - whilst still keeping the URL you typed. Neat huh!

Showing www.abcd.com/faq/ instead of www.abcd.com/faq/faq.html
call the file placed into the folder faq simply index.html (not faq.html) and then www.abcd.com/faq/
will display the page without the filename. (Make sure, you have defined index.html as a valid Directory index.)
There are more options with using mod_rewrite etc - but since you seem to use a prety static directory based navigation layout, that would be the easiest way.

Related

How do I make clean URLs (no file extensions) and also redirect from.html to .shtml at the same time without changing all my html code?

I wanted to use file extensions within the question body to make it clear as possible but the system kept throwing code errors at me when I hadn't used anything like code.
I have numerous pages that comprise a section of my website. Let's, for example, call the main page:
http://www.articles.mysite.com/
With in that, let's say some of the html files are:
"10things"
"extras"
"t7n"
"i2""
Essentially, the file names tie into what they contain, but they don't all follow the same name pattern for whatever reason (some are just numbers, some are numbers and some are numbers and letters together, for instance).
What I want to do now is upgrade these files so I can use serverside includes (SSI's) as I do on other pages of my website. However, I'm running into a couple of issues.
The URLs aren't clean (they have file extensions) and the same is true of links I've posted to social media, for instance. I'd like the resultant URL the user sees to not show these file extensions, partly for SEO and partly just to make it look less cluttered.
When I've tried upgrading the files by just changing their names, the links on my end appeared to work, but when using one of the social media links, I kept getting 404 errors so I started from scratch and kept trying to resolve the issues on my own. Unfortunately this hasn't worked and I'm now back to square one, with the links currently working with standard files.
To reiterate, I'd like the following to occur:
User clicks a link, whether directly on my site or on a social media site that takes me to a page on my own website.
Even if the link is one of the old ones, the user is silently redirected to the new version of the page, with a clean URL that does not include any extension for better readability and SEO purposes.
All this should ideally be able to happen without me needing to change the index files that store the links, only renaming the html file extensions.
The only two pieces of information that might be of help if I can figure out how to combine them are as follows:
This introduction to redirects, which references mapping file types as part of redirect matching with the same path and filename:
Could this be modified, changing the extensions used, to map the requests to the new renamed files from the old extension?
This previous question from Stack Exchange about rewriting and redirecting at the same time which talks about cleaning up extensions:
Could this be combined with the redirection in the previous question to make a clean and easy method of redirecting the user, cleaning up the extension and making it look as if nothing's changed with a file name being all that's required other than the above code?
You can use this code to redirect your .html page to .shtml page without changing any line of code.
#redirect .html link to .shtml link
RewriteEngine On
RewriteRule ^(.*)\.html$ $1.shtml [L]

Multiple index.html files inside folder structure

I just came up with an idea. Instead of using an .htaccess file to remove .html from the URL, why not just use a simple folder structure and in each folder add an index.html?
For instance:
example.com/index.html → Home
example.com/about/index.html → About
Now simply use a hyperlink on the homepage to the about folder, since typically index.html files are opened automatically.
The upside of this kind of navigation, is that it would be easily possible to create sub pages with no crazy database / .htaccess setup.
Now my question is: is there any reason not to create a webpage like that and is it legitimate to use multiple index.html files?
I appreciate all the help.
With the index.html route, there would be three URL's that can access the same page. For example for an about page:
www.yourwebsite.com/about
www.yourwebsite.com/about/
www.yourwebsite.com/about/index.html
Using the .htaccess file would likely give you more benefit from an SEO perspective. You can tell the search engine which one to use, by using 301 redirects. See more about how Google does this here:
https://webmasters.googleblog.com/2010/04/to-slash-or-not-to-slash.html
Of course you could set up your website using folders and index.html's, and still
use the .htaccess file to take care of the SEO. But, depending on your sites size and structure, this might be more work.
The only downsides would be having to create a folder in addition to a file whenever you want to create a new page, and having to take more time to navigate into a folder in order to edit a page.
As long as you are using Apache, or a similar server software, multiple index files will function normally and be served from each folder.

failed to load resource hexo.js

I'm using HexoJS to create a blog. I was able to generate the static files using hexo generate. Even though there are css files and JS files generated, they are not properly linked to the index.html.
So, I have to open each html page and correct each page links given in href and src attributes one by one. I believe that this is not very practical. Can anyone help ?
The localhost is used for preview the website. When we publish our blog, it should be on a server, then the path will be interpreted correctly, we don't need to change any thing. What we saw on http://localhost:4000 will be same when you published your website.
So, we don't have to worry about the broken paths in the public folder.

Setting Up A Html Page On A Server

I am trying to learn how to set up a html page on a server, which i have done but an index page appears, I do not want this page to appear i would rather my home page to appear.
I am only learning how to do this so i have used a free web host.
web address: http://testingmyfreewebsite.comxa.com/
My file manager looks like this
The subPages and Css folders were created by me and they contain the css and other pages to my website.
i would really like to know how to remove the index page i am open to many methods.
There are three commonly used default page names that you can use on most web servers:
index.html
index.htm
default.htm (on some Windows servers)
It's a good idea to stick with index.html or index.htm on most servers, as default.htm is most often used on Windows servers, and isn't as common as it used to be.
If you're going to put other pages inside of folders (or directories) each folder should have an index.html inside of it as well if you're relying on the url to direct the user instead of hard coding it in.

Is it bad practise to start links with "/" in html?

My website code sample:
<a href=/post/64/page-name><img src=/img-folder/2015/09/image.jpg></a>
<div id=cont2><a href=/post/64/page2>page 2 link</a></div>
My first question is, can I start links just with /? Is it a bad practise? because all website sources that I looked it starts with www.website.com/... not just /
Second question is quotes. It is not needed since html 2.0, but is it important in the example above?
My website is having some problems on google to show correctly... may it be because this problems?
It isn't bad practice. A URL starting with / is merely a relative URL that's relative the the base path. You're using it just fine.
Another example usage is when you want to reference a CSS or JavaScript file and you're deep down into the path.
<script src="/scripts/main.js"></script>
Then, no matter where the user is on your site, they'd always request http://example.com/scripts/main.js. Where example.com is your site's domain.
Additionally: Always quote attribute values. (attribute="value" and not attribute=value).
/ means start of where you are currently. So if your resource is located under same directory, you are allowed to use / to start with. If you refer to external resources, you can't use / to start. (E.g. www.google.com means google website, while /www.google.com means folder under your current directory named www.google.com, like http://localhost/www.google.com)
Quotes are needed when you use white-space in your attributes values (e.g. class="my super classs-name that has white-space" | class=my super classs-name that has white-space).
My website is having some problems on google to show correctly SEO stuff. What problems? Your page is not under first page of Google search? It's separate topic about that.
It is not forbidden. When you start your link with slash / it just a path relative to base element.
You can read more about BASE element here: http://www.w3.org/TR/html4/struct/links.html#h-12.4
For example, if you are already at: http://example.com/folder/index.html
/posts/index.html would link to: http://www.example.com/posts/index.html
posts/idnex.html would link to http://www.example.com/folder/posts/index.html
if you reference external sources you have to add the full path/adress
if you reference local resources its up to you.(more or less) take a llok at How to properly reference local resources in HTML?
You should use either double " or single ' qoutations - thats a good practise at least.
But you dont have to if there is no whitespace.
When you start your link with "/" its mean that you start from the root directory.
Example: Your website is in the directory /web/html.
When you now start your link with "/" its goes to the root folder. In this case the web folder.
I know this is old and answered, but it came up on Google when I was searching for something similar, so I just wanted to add to the answers.
Sometimes, when I need to do something real quick with simple HTML site that doesn't require a server, I usually just open index.html in Terminal to quickly preview the page in browser. However when you open your site like that, using the leading slash to load resources (ie. /js/main.js) won't work. That's because when you load your website by opening a file in your browser, the browser takes the root of your drive as the base path for your website.
So if you have your files like this for instance:
drive/Users/username/Documents/www/index.html
drive/Users/username/Documents/www/js/main.js
And you reference your script like this:
<script src="/js/main.js"></script>
The browser will think you're actually pointing here (if you open the file directly in browser):
drive/js/main.js
Because / in this case means drive and not the website's root (www in this case) folder as it would on a server.
Nope, it is not a bad habit to put '/' when starting links. But not having a quote in every html attribute? I don't think so. But i would suggest to put quote(") in every html attribute for it to be more readable.