Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to link to pages without the .html extension?

Tags:

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?

like image 278
user2451987 Avatar asked Jun 04 '13 13:06

user2451987


People also ask

How do I remove .html from URL?

The . html extension can be easily removed by editing the . htaccess file. .

Is .html the correct file extension for a Web page?

There's no difference between them, and you can use either on most web servers. As the original extension for HTML pages on Unix web hosting machines, . html indicates a file that uses HTML (HyperText Markup Language) or XHTML (EXtensible HyperText Markup Language).

How do I hide the URL in the address bar in HTML?

The only way to see a different URL is to proxy the response, or putting it in a frame. The only way to "hide" your URL would be to use frames.


1 Answers

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:

 <a href="http://whatever.com/wallpaper" title="wallpaper">wallpaper</a> 
like image 162
Mudassar Arshad Avatar answered Oct 20 '22 11:10

Mudassar Arshad