Forum Moderators: phranque

Message Too Old, No Replies

newbie mod rewrite and hash help

         

simunlastre

10:56 am on May 12, 2012 (gmt 0)

10+ Year Member



hello all,
im new in web design and i have a problem with htaccess
my link look like this: http://example.com/#!/about.html

it is ajax web page that never refresh onley url change

so it is posible to make my link look like http://example.com/about

if it is please help me

thanks

[edited by: incrediBILL at 7:10 pm (utc) on May 12, 2012]
[edit reason] fixed URL, use example.com [/edit]

phranque

12:56 pm on May 12, 2012 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld, simunlastre!

everything after the hash mark of a url is considered a Fragment Identifier:
http://www.w3.org/DesignIssues/Fragment.html [w3.org]
you can only make the link look like a new url path by having the user agent (browser) make a request for the new url.

simunlastre

1:32 pm on May 12, 2012 (gmt 0)

10+ Year Member



i didnt undrsten you, i found that facebook have a links like i need so do someone know how they replaced their urls?

g1smd

1:37 pm on May 12, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If you are using AJAX your link SHOULD include #!

simunlastre

2:24 pm on May 12, 2012 (gmt 0)

10+ Year Member



i know, but i wish my links in url to look beter, i fount this post [stackoverflow.com...]
but i dont undrstand it well, do someone of you guys know what they are speaking about?

lucy24

10:30 pm on May 12, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



To get everyone on the same page: Do you mean that your links contain the literal text #! ?

I started out assuming that you typed something else but the forums had censored it.

If it really says #! or #a or #blahblah or #anythingwhatsoeverinthewholeworld ... then you are out of luck, because the server doesn't see the hash mark (#) or anything that comes after it. Again, literally. The server simply does not know it exists, so it can't redirect it.

The # is officially called a Fragment Identifier. When your browser meets one, it tucks it away in its own memory, asks the server for anything before the #, and then reattaches the # to whatever it gets.

g1smd

10:43 pm on May 12, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



URLs with #! (hash bang) are specifically reserved for use with AJAX where Javascript in the browser looks out for such URL requests and takes appropriate action.

phranque

3:12 am on May 13, 2012 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



getting the non-hash-bang url to show in ajaxian applications is a browser history manipulation trick and is mozilla-dependent so it's not good for cross-browser compatibility.

lucy24

3:40 am on May 13, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



URLs with #! (hash bang) are specifically reserved for use with AJAX where Javascript in the browser looks out for such URL requests and takes appropriate action.

Yes, I gathered that. But it still comes down to "in the browser".

And then there are those rare cases involving fragment links in google searches...

simunlastre

12:08 pm on May 13, 2012 (gmt 0)

10+ Year Member



thaks you all for your answers, no luck then :)

i have one more question:
if i have a link like http://example.com/#!/about.html
can i remove .html extension so it look like http://example.com/#!/about

g1smd

12:10 pm on May 13, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yes - the links on your pages should point to the URLs that you want users to see and use. URLs are defined in links. You then adjust your code to accept those URL requests.

simunlastre

3:16 pm on May 13, 2012 (gmt 0)

10+ Year Member



hmm, can you explain me a litle more?

i tryed make a link like this
<a href="#!/about">About</a>

and .htaccess like this
RewriteEngine On
RewriteRule ^#!/about$ #!/about.html

but i cant get it to work...

phranque

10:06 pm on May 13, 2012 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



the server will never see the hash mark.
it is a fragment identifier - as in it identifies a "fragment" of the current document.
in the hash bang case, javascript is often used to make an http request but the hash tag won't be in the requested url.

lucy24

12:16 am on May 14, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



OK, now how does it work if the "html" element-- or the absence of an "html" element-- comes after the hash?

If your original link says, literally,

http://example.com/#!/about.html
or, in the alternative,
http://example.com/#!/about

what does the server see, and what can it do about the "html"? Do you have to perform some kind of jiggery-pokery with your ajax script instead?

phranque

6:27 am on May 14, 2012 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



the server sees whatever the javascript requests when it sees the hash bang and whatever follows.

g1smd

6:55 am on May 14, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



With a normal HTML page, when you click a link the same URL as shown in the link is directly requested from the server (the server may optionally rewrite the request to fetch the content from some other place inside the server, different to what the path part of the URL request might have implied for that internal location).

With an AJAX page, when you click a link the Javascript code running in the browser detects what you did and the Javascript function makes a different URL request to the server. You are going to need to modify the link on the page to show what URL you want to have, and you'll also need to modify that Javascript code to "look" for that link being clicked.

However, having said all that, and since hash bangs are now an established standard I would leave well alone.

simunlastre

10:18 am on May 14, 2012 (gmt 0)

10+ Year Member



i realy want to remove that html from url, it will be more beautiful, do someone know any good tutorial that will help me?

[edited by: incrediBILL at 2:36 pm (utc) on May 14, 2012]
[edit reason] URL removed, no self-promotion or sigs [/edit]