HTML Fallback Page - html

Is there a way I can set a 'fallback' page?
For example, my technique for updating pages on my website is to firstly remove my original index.php and then replace it with a seperate index.html that reads "We'll be back soon!". This is to explain that all pages are down for maintenance (as I upload updated content).
This means anyone attempting to access my home page will be greeted with the maintenance message. The problem, though: if someone manually types in the URL of the page they are trying to access they would instead be resulted with a "Page not found" error.
Is there a way in which I can direct the user to index.html if they are attempting to visit a location that does exist - but just not right now (since I removed it to update content) ...if that makes any sense ;D

Assuming this is an Apache (or compatible) web server, place an .htaccess file in the document root directory (where your index.html usually goes) and put theses lines in it:
RewriteEngine on
RewriteRule ^ maintenance.html
This makes the web server respond to any and all requests with the maintenance.html file. Obviously, put your "under maintenance" web page there. You'd need to tweak that a bit if you wanted to serve images on that maintenance page, but this should get you going. See https://stackoverflow.com/a/20563773/476.

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]

Change index.html into start.html

Please I hope somebody can help me because i've been dealing with this problem already for about 2 weeks and I just can't figure out how to fix it.
I have added a new part to my website since I'm offering a totally new service. I put the new part under index2.html.
I have a new start/default page called start.html, on here they can choose to click on the service they are coming for, so will be either going to the old website part which is under index.html or they will go to the new part which is under index2.html.
To have people go directly to start.html I have put DirectoryIndex start.html in my htaccess file and this works fine. But when they choose which website part they want to go to and click on it they don't get the website index.html or index2.html but they get a message in the screen that their connection is not private and you will see a red https in front of the url link. I don't want it to be https, it just needs to be http.
Individually all the links work fine. So I don't understand why the message appears and what can I do about it?
I also did a link check on W3C, it said:
error Line: 87 www.example.com/index2.html
Status: 500 Can't connect to www.example.com:443
This is a server side problem. Check the URI.
error Line: 78 https://www.example.com/index.html
Status: 500 Can't connect to www.example.com:443
This is a server side problem. Check the URI.
Using index.html as the default file for /folder/,
ie. pointing the browser to /folder/ takes you to /folder/index.html
is such a widespread convention, you are almost definitely better off not messing with it.
My suggestion would be:
Rename /index.html to /old-part/index.html
Rename /index2.html to /new-part/index.html
Rename /start.html to /index.html
I concur with Rounin. A browser/website is designed to look for a file called index.html, index.php, index.xhtml, and so forth for the main page of the site depending on the type of website it is when it comes to your domain.
You need to do what Rounin suggested for your files to maintain a proper website without any headaches.

Use history.pushState while ignoring/bypassing .htaccess (alternative solution welcome)

What I'm trying to do is have a single dynamic file that takes a parameter to affect content (/view.html?k=about) but uses history.pushState to change the URL to something more user-friendly (ki/about). In addition, anytime an AJAX call is made on content.html to load new content, it updates the URL according, (e.g. if products are loaded via AJAX, change URL to keywords/products).
My current solution is any path requested from ki is redirected via .htaccess to the view.html page. view.html then uses history.pushState to change the URL. As links are clicked, the URL updates. The problem with this, however, is it causes a infinite loop.
Here is my .htaccess file, residing in the /ki/ folder.
RewriteEngine on
RewriteRule ^(.*)$ /concept/view.html?k=$1 [R=permanent,L]
What can I do to get my desired result? If there's a way to achieve the same thing without the .htaccess file then that's acceptable too.
You are going to want to rewrite any url that goes in the form of ki/about to the /view.html?k=about behind the scenes.
history.pushState is only really meant to be used for web applictions like Spotify that don't reload the page but would still make sense to have the back button have some functionality.
That way, urls can be shared without giving 404 pages.
I have not tested this but I am sure you want something like this
RewriteRule ^ki/([A-Za-z]+)/$ /view.html?ki=$1
If the user types in the ugly url, they will still get to the same page no problem. But the pretty urls will direct users to the right webpage.
For more info you can go here.
http://www.yourhtmlsource.com/sitemanagement/urlrewriting.html

Hiding page names in the browser

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.

Do I need slashes before links?

When I code my website, on my local computer i can use
blablabla.
However, I also can see this type of thing on other places as
blablabla.
I am not sure what I will need when my site goes live. If I try to do this on my local computer, it doesn't understand it. My question is, if I post my site up like this, will it work?
Ok, if I have all of the files of my site in the root directory that the main index.html file is located in, will it work when it is being hosted?
If you do not use a slash, the link will point to index.html in the same folder as the page the link is on.
For example, if you have a link to index.html on the page www.example.com/page2.html then the link will take you to www.example.com/index.html. If you include a slash, it will do the same thing.
However, if the link is in a page in a subfolder, like www.example.com/projects/page2.html, then the first link will take you to www.example.com/projects/index.html while the second link will still take you to www.example.com/index.html.
The slash denotes the "web root."
Note that these are still considered "relative" links: they refer to a resource on the same server, regardless of the server's name. If your domain name changes or you upload it to another server, relative links will still work provided they have the same folder structure.