get rid of .html in url

Closed Office

Verified User
Joined
May 9, 2008
Messages
17
Location
Calgary, Alberta
I would like to be able to use mainlytext.com/bike instead of mainlytext.com/bike.html. I did search and find a couple of threads about doing it in cpanel, but haven't been able to get them to work. Also, since the site has been up long enough to get some links with the .html, I guess I need to be able to redirect one version of the url so that they both work. What is the best way of doing that? (embarrassed newbie question)

best wishes, lloyd
 
Well, this is going to be slow. Thanks for the reply. Now I'm trying to understand what he means by the #1 thing I should do, "Edit your pages to link to extension less URLs." How do I do that?

And the second doesn't seem easier. "Add mod_rewrite code to internally rewrite those URLs, when requested from your server, to the correct-extension file." I did git a lot of pages about this from Google, so I guess I'll start there.

best wishes, lloyd
 
Well, this is going to be slow. Thanks for the reply. Now I'm trying to understand what he means by the #1 thing I should do, "Edit your pages to link to extension less URLs." How do I do that?
Wherever you now link to filename.html you need to edit that to link to filename.

Jeff
 
Try using apache's mod_rewrite - you'll have to add a short .htaccess file to make this working
 
Well, this is going to be slow. ..... Add mod_rewrite code ..... I did git a lot of pages about this from Google, so I guess I'll start there.

If you do not know how to edit hyperlinks in your html code then you probably should start with a html tutorial. If you don't understand html you will never understand mod_rewrite.
 
"Wherever you now link to filename.html you need to edit that to link to filename."

OK, so one of the pages is mainlytext.com/bike.html I copied the code from it and pasted it into a file in the public folder called bike. I guess this can't be what you mean because one problem is that I can't edit this file, the option just isn't there in the public folder, and a second problem is that when I enter mainlytext.com/bike in the browser bar, I don't get a web page, I get the code page that you would normally edit, complete with <p> etc.

If I delete that page and just use the link mainlytext.com/bike I get a page not found on this server.

So, still wondering.

best wishes, lloyd
.......__o
.......\<,
....( )/ ( )...
 
OK, so one of the pages is mainlytext.com/bike.html I copied the code from it and pasted it into a file in the public folder called bike

Why would you do that? You are supposed to edit the links.
 
Why would you do that? You are supposed to edit the links.

It was just another thing I tried. As I mentioned in the same post, when I just use the link mainlytext.com/bike I get a file not found on this server. Is there another way I should edit the link?

best wishes, lloyd
 
You leave the name of the file bike.html in place. You edit the file that has the link to bike.html so that the link does not have the .html. Then you have to create a .htaccess file with some mod_rewrite rules so that every time somebody clicks on the link for the file bike the file bike.html is displayed.

This is the same thing that was said by rtaylor, jlasman, and vovaNux. We pointed you in the right direction.

The other thing you can do it edit the link so that it does not have the .html for bike.html. The create a folder called bike. Copy bike.html into the folder bike. rename the bike.html file in the bike folder to index.html. Then you do not have to learn mod_rewrite rules.
 
Thanks for the extra details and the time you took to post them. This actually sounds really interesting now. There was more to "edit a link" than I realized. I do have a simple follow up question. Would either of these 2 approaches (first paragraph, .htaccess, or last paragraph, file within a folder) work with both types of links, with .html and also without it? Or I suppose there would be an extra step in each to make that happen?

bye for now, lloyd
 
There was more to "edit a link" than I realized.

Not really. You open the file and backspace over the .html in the link.

If you want both extension and extensionless urls and links to work then you will either have to get really complicated and use mod_rewrite or you will need to leave bike.html and also create a folder called bike and copy bike.html into it and rename it to index.html.

Also if you have command line access you can create a symbolic link from bike to bike.html.
 
Back
Top