: Organizing website files I want to start creating my website but I have a few questions. http://website.com/directory/webpage - in this kind of website, it does not display a .php or .HTML extension
I want to start creating my website but I have a few questions.
website.com/directory/webpage - in this kind of website, it does not display a .php or .HTML extension at the end. How to achieve this?
if I have several pages like contact.html, aboutme.html etc Should I just create separate html files, or should I do something in one main index.php file and use PHP or JavaScript to handle the content according to the URL. Which is a more appropriate workflow?
More posts by @Vandalay111
3 Comments
Sorted by latest first Latest Oldest Best
The simplest way of achieving URLs without .html in them is often to make a directory called webpage and have a file called index.html in it. The file is actually
website.com/directory/webpage/index.html
but you can link to it as
website.com/directory/webpage
Apache (and most other systems) have a configuration setting for which file names should be treated as indexes for this purpose.
It is not a good idea from an SEO point of view to serve different content via Javascript since a web-crawler is likely to either see an empty page or always the default content. In either case, your content will not get fully indexed.
Serving different content via PHP is doable and some entire sites are served by only a single file. Those sites usually have a content management as a back-end which works that way or not. If you are to write your own site, it would mostly likely simply make it harder to develop and maintain.
The serving-without-extension part of your question has already been answered with two good ways. There are other variants depending on how your side is organized but generally you use Apache's RewriteEngine.
There are several ways to serve files without an extension.
One of the easiest is to use the Multiviews option in your .htaccess. That option allows the /webpage.html document to be accessed through the /webpage URI. Then you can use a rewrite rule to make sure that the version with .html gets redirected to the version without the extension. Here is the .htaccess:
Options +MultiViews
RewriteEngine On
RewriteRule (.*).html [R=301,L]
Another way of doing it is having your entire site be handled by a single script that prints the correct page based on a parameter, and then use .htaccess to rewrite everything into that script. Here is the .htaccess for that approach.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /thescript.php?s= [L]
Many content management systems (CMS) such as Wordpress name your URLs for you, and have settings for the style of URL that you wish to use. In Wordpress this can be controlled under "Setting" -> "Permalinks" where there are several options, none of which use the .html extension. I also use the custom permalinks plugin that allows me to specifically choose the URL that I want for every page.
As for your question about the number of pages on your site, it is common practice to have separate pages for contact.html, about.html, privacy.html, and faq.html. I could see merging contact information with "about us" information, but I wouldn't try to put everything in one page, it gets too long.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.