FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


simple URL redirection





Da Rossa
Hi!
In my site I have many html files, like the usual. In the root itself I carry many of them, so they're in the same level of index.html. Let's say I have another file in the same root directory in my site, named example.html. "example", actually, corresponds to a simple, easy-to-remember word. But I always need to tell people to add the "dot H-T-M-L" after typing, which is not good. My site is http://notasdeaula.org, and, when typed, it points to index.html. what I would like to is, when I type http://notasdeaula.org/example (not example.html), it redirects to example.html.

Uploading an extensionless .html file will, obviously, not work; it will just open the plain text containing the html code.

Long ago I heard that it has something to do with a .htaccess (or something) file, but I just couldn't get it.

What should I do?

p.s. i use DirectAdmin.
Peterssidan
It has been some time since I worked with .htaccess files so I might be wrong, but I think you can use the following script:
Code:
RewriteEngine on
RewriteRule ^([a-z]+)$ /$1.html [NC,R=301,L]

Put it in a file named .htaccess at the root and it should work, I hope (not tested).
Da Rossa
I uploaded the .htaccess file to the root, and renamed a file removing the .html extension. So I access http://notasdeaula.org/social55 and... all I see is the html file in plain text. Why?

And thanks for the help so far!
cr3ativ3
Da Rossa wrote:
I uploaded the .htaccess file to the root, and renamed a file removing the .html extension. So I access http://notasdeaula.org/social55 and... all I see is the html file in plain text. Why?

And thanks for the help so far!


Because what you have intern done by renaming the file after uploading the .htaccess script, is bypassing the .htaccess rules all together.

Rewrite rules in .htaccess are ment to change how the end user accesses files on the server, without having to change any files on the server.

The short answer to your issue, is add the .html back onto the file that you removed it from.

What the .htaccess has done, has told the server to take any requests for http://notasdeaula.org/social55 and look for a file named social55.html in the root web directory and load it.

Make sense?
Da Rossa
Yes it does make sense! But this is still unfunctional so far Very Happy

Let me tell you: although I didn't perfectly understand what you said in

Quote:
Because what you have intern done by renaming the file after uploading the .htaccess script, is bypassing the .htaccess rules all together.


... I followed your tip at

Quote:
The short answer to your issue, is add the .html back onto the file that you removed it from.


and put back on the .html extension in the file social55.html.

Thing is: when typing http://notasdeaula.org/social55, I'll, again, see the html code in plain text instead of the rendered page itself.

Please don't give up on me...
Peterssidan
The script I gave you only works for files with only letters in the name.
Change to the following to make it work with digits too.
Code:
RewriteEngine on
RewriteRule ^([a-z0-9]+)$ /$1.html [NC,R=301,L]

If you like to allow other characters like - and _ in the filenames you just add it after a-z0-9, I think you will have to escape - like this \-
Nemesis234
pretty sure you could just create a folder named "example" and in there put a file called index.html, and in that index.html have it link to .example.html

saves messing around with hta access and all that crap.
Da Rossa
Quote:
If you like to allow other characters like - and _ in the filenames you just add it after a-z0-9, I think you will have to escape - like this \-



Nice! It's working! Almost there!
Yep, I need, the - and _ characters. So I followed your tip and wrote:

Code:
RewriteEngine on
RewriteRule ^([a-z0-9\-\_]+)$ /$1.html [NC,R=301,L]


...but it appears to be incorrect. What's wrong?

Quote:
pretty sure you could just create a folder named "example" and in there put a file called index.html, and in that index.html have it link to .example.html


I got the intention, but how exactly would I do that? I mean, how to have a file automatically link to another?
cr3ativ3
Da Rossa wrote:

...but it appears to be incorrect. What's wrong?

Quote:
pretty sure you could just create a folder named "example" and in there put a file called index.html, and in that index.html have it link to .example.html


I got the intention, but how exactly would I do that? I mean, how to have a file automatically link to another?


Without using .htaccess, you could use php to transparently make "/sample55" appear to be "/sample55.html";

Inside the sample55/ folder create a file (index.php), make sure you dont have any other directory index in that folder like "index.html", the contents of the php file would be:

Code:

<?php
include("../sample55.html");
?>


That would simply use php to include the contents of the file sample55.html one directory above the current (../).

Or if you want something less transparent you could use a simple meta redirect inside the "index.html" file within your "sample55/" folder.

Code:
<meta http-equiv="refresh" content="0;url=../sample55.html">


However I hope the .htaccess will work out for you, it's really how it should be done.
Peterssidan
Da Rossa, are you sure it doesn't work? I write /exa-mple and it redirects to /exa-mple.html and /exa_mple redirects to /exa_mple.html. Of course I get the error page because the pages don't exist but it works!

The directory method that cr3ativ3 and Nemesis234 talks about is not very convenient. You have to add one directory with one php (or html) file for each file instead of just making it work once and for all with one .htaccess file.
Nemesis234
Peterssidan wrote:
Da Rossa, are you sure it doesn't work? I write /exa-mple and it redirects to /exa-mple.html and /exa_mple redirects to /exa_mple.html. Of course I get the error page because the pages don't exist but it works!

The directory method that cr3ativ3 and Nemesis234 talks about is not very convenient. You have to add one directory with one php (or html) file for each file instead of just making it work once and for all with one .htaccess file.


yea, maybe, but that rewrite rule means that you have to have a "/" at the end of the directory to enter index.html, otherwise you will end up at the directory.html which is maybe not what you wanted.

if his users are seemingly struggling to work out they have to add .html after the file, is it also possible they will forget the / sometimes aswell? and end up in a completely different place then they planned to be.

with this edit to the .hta will make this site different to all other sites, i have never come accros 1 site that forces me to another page if i forget the / at the end of the directory, there is always an index file to redirect/display what i actually wanted
medesignz
/example/index.html

containing
Code:
<meta http-equiv="refresh" content="0;url=../example.html">
[/code]
Related topics
why no hosting under .com
image
URL redirection
Perl server referencing
Cheap .be Top level Domain Services
URL Redirection Error?
How to config domain setting in DirectAdmin
How To Copyright
REDIRECTION
.COM Domain for Frihost
URL Redirection - Javascript+HTML, so simple...
Master Tutorial on SEO
Favorite CMS.
Dominios Gratis ( tk, co.cc )
Reply to topic    Frihost Forum Index -> Support and Web Hosting -> Web Hosting Support

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.