How to personalize my website url and remove file extensions? - html

I’m planning in doing a web site for a personal project and I would like to personalize the URL but I couldn’t find how to do that.
Instead of the url being www.mywebsite.com/example I would like to change to www.example.mywebsite.com.
Another thing that I would like to do is remove the file extension, i.e.: www.mywebsite.com/example instead of www.mywebsite.com/example.html
I think that these stuff need to be done in .htaccess but I don’t have idea how to do it.

the first point you can do with subdomains, that you see in your hosting account or question with technical support. The second point of the extension of the html you can do in the .htaccess as you say:
If you want to remove the .html extension from a html file for example yoursite.com/wallpaper.html to yoursite.com/wallpaper you simply have to alter the last line from the code above to match the filename:
RewriteRule ^([^\.]+)$ $1.html [NC,L]
Source: https://alexcican.com/post/how-to-remove-php-html-htm-extensions-with-htaccess/

Related

.htaccess rewrite cond for adobe muse

I have an adobe muse site that office staff update. However I want to add an html file at the top level so that I have example.com/recruitment-advertising.html minding its own business and just working separate from adobe muse.
I have tried to exempt the file from muse in the .htacess file using a condition but the page keeps coming up
Page Not Found
We could not find the Web Page you requested. This is either because:
There's an error in the address or link. Or you have entered the
address or link incorrectly.
It is probably syntax, but I can't seem to get it to work.
My .htaccess file currently looks like
# Begin Muse Generated redirects
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/recruitment-advertising\.html$
RewriteRule ^muse_test_redirect.html$ muse_test_redirect.php [L]
</IfModule>
# End Muse Generated redirects
I don't think relevant but all the resources for that page are in a lower folder at example.com/landing
I want the page at top level, because its a landing page and I don't want it several folders in as google doesn't think things that deep are so important.
I don't care if the solution is something entirely different and not using .htaccess, I just want my html page to run on the domain. Many thanks in advance.

htaccess- only one page redirects from html to php

This is normal question, but i am very weak regarding .htaccess
I have one website in html.All Pages are in .html. Now only enquiry page is enquiry.php
So I want enquiry page from enquiry.php to enquiry.html in URL.
It should not affect other html files
Pls help
Provided you've already turned "RewriteEngine On" your rule might looks something like this:
RewriteRule ^enquiry.html$ /enquiry.php [QSA,L]
However depending upon your web host, that may not work out of the gate. For example, you might need to add a slash before the .html so it would read:
RewriteRule ^enquiry\.html$ /enquiry.php [QSA,L]
I've also seen where you may need to add "Options FollowSymLinks" to the top of the .htaccess file.

Removing the index.html from url

Ok, maybe a pretty dumb question but I can't find an answer on Google.
I am coding my site by hand. How do I make the index.html disappear from the url's? Do I use a piece of code in my html? Do I have to change my href's in my files?
Hope you guys can help!
EDIT:
I've tried this with a .htaccess file
RewriteEngine On
RewriteRule ^index\.html$ / [R=301,L]
RewriteRule ^(.*)/index\.html$ /$1/ [R=301,L]
It does work, but all my links aren't working anymore. I discovered I had to remove all the index.html from the href's in my documents. But that would be a lot of work. Is there an other code for .htaccess that just hides index.html?
A SIMPLE WAY TO DO THIS in Html:
(example in my case is a simple dual language site)
If your link looks like this:
Homepage
You should change it to this:
Homepage
If trying to link to another folder in your directory, like is my example:
English language
You should change it to this:
English language
Notice that "/" goes back to your root directory and automatically selects index.html, so that is why I used "en" for the English language site, because the name of the folder in that case is "en". You should also make sure that you have index.html in your English language folder, and not index-en.html.
Apache has .htaccess files and mod_rewrite,
In your .htaccess file, set:
DirectoryIndex index.html
You can also set this up in the Apache site config files too
You can specify a list of filenames, so if it doesn't find the first it moves to the next.
IIS has .config files
mod_rewrite module is responsible for all the rewriteEngine. Check on your server whether is module is present and enable.
You need to create a file called '.htaccess' in the root directory of your site containing the following code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
And then make sure all the links on your site don't contain '.html' at the end, e.g.:
<a href="/Home.html">
should be replaced with:
<a href="/Home">
Hope this helps!
if you dont find .htaccess, you just need to create a new file using your text editor the same way you would any other html or css file, but save it as simply '.htaccess'
And save it into the root directory, so the same folder that you have your index.html file.
I think this is configured in IIS when you deploy the site, I'm not to sure on it but I'm sure you can specify a start point that your URL will use when you just enter the UL, that implies the Index.html page.
Sorry I'm not too helpful here, hopefully it will point you in the right direction.
Often these things such as Apache or IIS have this set up already, and it looks for the Index.html, Index.php first when you just put your URL in.
Great SEO idea! This is similar to nginx redirect loop, remove index.php from url and Apache .htaccess to hide both .php and .html extentions, as well as mod_rewrite not working htaccess — the idea here, for both Apache's mod_rewrite and nginx ngx_http_rewrite, depends on the differences between the external and internal URLs — in order for the redirect from /index.html to / work, yet not cause redirect loops when actually serving index.html, you gotta make sure you only issue the redirect for external index.html requests, but never for internal ones; this can only be accomplished by looking into the actual request_uri.
Here's the code for nginx ngx_mod_rewrite:
index index.html index.txt;
if ($request_uri ~ "^(.*/)index\.(html|txt)$") { return 301 $1; }
On Apache's mod_rewrite, it'll be something like the following:
RewriteEngine on
RewriteCond %{REQUEST_URI} ^.*/index\.html$
RewriteRule ^(.*/)index.html$ $1 [R,L]
Related:
nginx redirect loop, remove index.php from url
Apache .htaccess to hide both .php and .html extentions
mod_rewrite not working htaccess
References:
http://nginx.org/r/index
http://nginx.org/r/if
http://httpd.apache.org/docs/current/mod/mod_rewrite.html#RewriteCond
Change the link that goes to your homepage to the website address.
You may have:
Link Here
Change that to:
Link
Or try this
Simply don't type the index.html in your browser and don't advertise it as such.
You can set the 'default document' on the web server (whichever you happen to be using) to serve 'index.html' in the absence of a file part. This way, someone going to http://www.mysite.com would be served http://www.mysite.com/index.html

How to link to pages without the .html extension?

I would like to link to pages inside my website, e.g:
Not: mywebsite.com/about.html But: mywebsite.com/about/
I've seen various websites doing this but it looks like they also react differently to things:
Apple.com:
apple.com/iphone/ works, apple.com/iphone/index.html works, apple.com/iphone redirects.
Opera.com:
opera.com/mobile/ redirects, opera.com/mobile works, opera.com/mobile.html does not work.
Mozilla.com:
mozilla.org/en-US/ works, mozilla.org/en-US redirects, mozilla.org/en-US/index.html does not work.
Which leads to another question: Are there different methods for this?
Edit:
It seems that Apple uses a folder for every page, e.g. a folder called 'iphone' with an index.html file inside it?
But Opera and Mozilla use something in the .htaccess file?
Removing Extensions
To remove the .php extension from a PHP file for example yoursite.com/wallpaper.php to yoursite.com/wallpaper you have to add the following code inside the .htaccess file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
If you want to remove the .html extension from a html file for example yoursite.com/wallpaper.html to yoursite.com/wallpaper you simply have to alter the last line from the code above to match the filename:
RewriteRule ^([^\.]+)$ $1.html [NC,L]
That’s it! You can now link pages inside the HTML document without needing to add the extension of the page. For example:
wallpaper
They are using .htaccess and URL rewriting. This is part of server configuration. You can not do it with html only.
This page explains basics of URL rewriting.
You folder then has to contain a file: index.*.
Like: /iphone/index.html, which can be /iphone/ as well
Or work with .htaccess
In the .htaccess file in your sites root folder just add the following line:
# ---- Render pages without urls
Options +MultiViews
The most upvoted answer doesn't check whether the URL points to a directory, so you're going to get some mysterious 'not found' errors when it tries to append '.html' to a directory path. Easily fixed:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ $1.html [L]
The first condition will only pass if the path does not point to a valid directory. The second will only pass if the path points to a valid file when the .html extension is added. If both conditions pass, the rewrite rule simply adds ‘.html’ to the filename.
Notice that we can just match the entire path with .*. You can reject paths that contain a period character if you wish, but it's not really necessary since you've already checked that {REQUEST_FILENAME}.html is a valid file. In any case, it is unnecessary to escape a period character when it's inside a character class. I know you see this [^\.] everywhere, but the slash is redundant. [^.] is how to write it and look like a regex pro. 😎
This kind of redirect will be invisible to the user because, by default, mod_rewrite does the substitution internally, without informing the browser. If you wanted to do a permanent redirect, you would add the [R=301] flag at the end.
Alternatively, as Genus Amar said, you can just enable the Multiviews option on a per-directory basis by adding this Options Directive to the .htaccess file:
Options +MultiViews
It's worth adding that this will only work if the server administrator has enabled MultiViews with the AllowOverride Directive, and it won't allow you to perform additional redirects.
Neither of these solutions (on their own) will remove the .html if it’s part of the requested URL. If you want to do that as well, see my answer to this question.
Make your href attribute equal to the page you want to link or .. If you need to
move up a directory.
Ex: href="contact.html"
Ex: href="../links/contact.html"

Style Sheets and hiding .html extension

I'm not amazing with web stuff but I have a small portfolio site which I am redesigning. I am looking to hide the example.com/page.html and make it website.com/page.
I added the rewrite engine which I found on here for the .htaccess
RewriteEngine On
RewriteRule ^([A-Za-z0-9-]+)/?$ $1.html
The only problem is that when I use the RewriteEngine, the original path of /page.html loads as normal, but when i test it as /page/ it seems to lose the style sheet, I've tried relinking the style sheet as .../style.css instead of just style.css, but still all the images and style sheet seem to go missing.
It's probably something pretty damn simple but I need some help here.
what i understood from your words is that you want to make your url like :
http://www.example.com/page
ok . if you don't have to use htaccess , you can do this to do what you want .
just change the file name (page.html) to (index.html) . now create a new folder in your root and move the index.html to there !
and if the file , (page.html) is your home page , just change its name into index.html and leave it alone :D !
Your problem doesn't necessarily have to do with the RewriteRules, but with paths. You should, in general, always use absolute paths to images and assets. So instead of loading style.css or ../style.css, load /style.css or /static/styles/style.css. Otherwise the browser tries to resolve relative to the page location, and /page is considered to be in the root folder while /page/ is thought to be its own folder.
Iow, if you load style.css from your page:
From /page it will load /style.css
From /page/ it will load /page/style.css
Always use absolute paths, save yourself the pain and frustration.
Apart from that, ensure the images and assets are also not rewritten into .html extensions as mentioned in the other answers.
You probable don't want to rewrite every possible extension, so you might want to try something like this:
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
What this should do is check to see if a file exists with an .html extension. If it does it should transparently append .html to the path prior to doing the actual "lookup". So, if you make an HTTP request for
http://yourdomain.tld/somepage
and your site has an HTML page called somepage.html, the actual URL that gets processed will actually be
http://yourdomain.tld/somepage.html
EDIT:
I'm including a Dropbox link for a self-contained example that shows the suggestion above works: https://www.dropbox.com/s/6md9gviv0r2rf9v/xampp.7z
It contains a portable version of Xampp + the source files from this rather nice tutorial: http://coding.smashingmagazine.com/2009/08/04/designing-a-html-5-layout-from-scratch/
Unpack the xampp.7z file somewhere (I recommend the Desktop) and then find and execute the setup_xampp.bat file. It will adjust all the internal paths to your local filesystem. Then, run xampp-control and start Apache. Once that's running, navigate to http://localhost:8080/testsite/ - this is the test site. You should be able to bounce back and forth from http://localhost:8080/testsite/ to http://localhost:8080/testsite/contact - both pages have a .html extension.
HTH.