Zouz.me
Zouz.me

Reputation: 11

Rewriting a URL

I developed my website so that all pages are loaded dynamically on 1 page by ajax, and so that the URL will appear in this format:

www.website.com/#home
www.website.com/#news
www.website.com/#news-details/news-title-goes-here

I discovered later-on that my pages aren't appearing in search engines and Google bots won't visit me this way. So what's the easiest way to fix it and convert URL into this form:

www.website.com/news/news-title-goes-here

Could it be done with just modifying .htaccess ?

Upvotes: 0

Views: 82

Answers (3)

Zouz.me
Zouz.me

Reputation: 11

I followed this link:

https://developers.google.com/webmasters/ajax-crawling/ 

Converted all my dynamic pages to appear in this way:

www.website.com/#!home
www.website.com/#!news
www.website.com/#!news-details/news-title-goes-here

(added the ! after the Hash)

Then generated Html snapshots dynamicly. (however I made them in only 1 file html-snapshot.php) So now I had 2 types of URL:

the Ugly one:

www.website.com/html-snapshot.php?_escaped_fragment_=news-details/news-title-goes-here

and the pretty one:

www.website.com/#!news-details/news-title-goes-here

I added all the pretty URLs into a sitemap and submitted in Google Webmaster, and Fetched all the Ugly ones in the webmaster tools "Fetch as Google"

and in summary that's it, Google is now seeing all my ajax pages.

Upvotes: 1

Fanmade
Fanmade

Reputation: 306

That's a pretty basic SEO vs coolnes problem. If you like to keep the way your page is behaving, you could add a static version in parallel.

The following code in your htacess routes any request back to your index.php where you can select output the content based on those values.

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /index.php

I'm writing this with my phone while sitting in the train (bored) so please excuse if the formatting isn't perfect ;)

Edit: I nearly forgot; you get the url like this when using this method: $url = $_SERVER["REQUEST_URI"];

Upvotes: 0

Robert82
Robert82

Reputation: 490

The problem is that Google is getting confused. You may have inadvertently stumbled into a cloaking situation.

If you look at other sites that have dynamic content loading on a homepage (like a news site), that content is eventually linked back to another content page (with it's own URL). When you introduce pound/hash signs into your URL, Google is seeing that as an anchor point on the same page it was on before (this is the traditionally accepted use of hash in a URL), and expects to see all of the same content. If you're keying on this hash and loading completely new content it's causing Google to be confused.

If Google is hitting the same URL and getting different content from AJAX calls, and it can't figure out that the different content is actually coming from different "pages" then Google could interpret this as cloaking, and drop your pages from the index.

Here's another thing you can try; hashbang URLs: https://developers.google.com/webmasters/ajax-crawling/docs/getting-started

Upvotes: 1

Related Questions