evan.stoddard
evan.stoddard

Reputation: 698

Scroll webpage based on url

So I'm building a website that's basically one page but the links at the top just scroll to a different location on the page. Here's an example: http://evanstoddard.site90.net.

If I were to give a link to, in the example above, the about page I would simply give that person a link that looked like http://evanstoddard.site90.net/#about and that link would go to the about section of that website.

Let's say I wanted to do the same thing except instead of adding the '#about" I would use /about. So it would end up looking like http://evanstoddard.site90.net/about but do the exact same thing as #about. This would be better for SEO I'm assuming.

Any help would gladly be appreciated. Or even a "you're crazy... it will never work" ;)

Long story short, I want to display 'http://evanstoddard.site90.net/about' and have it do the exact same thing as 'http://evanstoddard.site90.net/#about'

Upvotes: 0

Views: 121

Answers (1)

MaGnetas
MaGnetas

Reputation: 5008

You're not crazy at all and it will work :)

You should edit your .htaccess so that everything after your domain would be sent to the same page (index.php I assume) as GET params and work from there. Now you can get the URL on page load using javascriptO OR "digest" the parameters in PHP and output it to the client side. jQuery scrollTo might help you with scrolling to whatever you need.

That's how it might be done in .htaccess (that's how it's done in Kohana):

RewriteRule .* index.php/$0 [PT]

And this should help you with scrolling.

Upvotes: 3

Related Questions