My Rule: RewriteRule ^(.*)/album/(.*)/?$ watch_album.php?id=$2&video_url=$1 [L]
when i goes to site:epashto.com in google search it shows me url with query string

like : http://epashto.com/watch_album.php?id=33

but my SEO Friendly URL is: http://epashto.com/special-hits-volume-4-pashto-songs-album-2013/album/33

Now the issue is that if user click to this url: http://epashto.com/watch_album.php?id=33 it should redirect to my new SEO Friendly URL Automatic or if someone just type the ugly url direclty in address bar and hit enter button it show change to my new url is this possible or not if yes then please help me, my enternal website url work fine and its SEO friendly but google is indexing ugly urls how to prevent it from indexing ugly ur n redirect those urls to new patterns thanks!

Recommended Answers

All 4 Replies

how to prevent it from indexing ugly

Well, first you have to make sure that you do not have any links on your site or any links published anywhere on anyone else's sites that include the query string in your URL. If you do have those links published, Google's web crawler is going to find them an index them. If you dont have those links anywhere, Google wont find them.

Your objective should be to ONLY publish the nice SEO links and have your URL rewrite rules take care of providing access to the correct page by rewriting the URL to include the query string. If you do this correctly, the URL in the browser will only show the SEO friendly URLs, not your URLs with the query string included.

Now the issue is that if user click to this url: http://epashto.com/watch_album.php?id=33

Why would the user click on this link? You should not have these links anywhere on your site. Only SEO links should be published.

Thanks jorgeM for your kind reply!
I know about your saying already, and i take care about it from the first day when i developed this website and the script.
Open up Google.com
Search with this --> site:epashto.com
you will find the URL in the ugly format, but also the url with SEO friendly exist on the last pages of the google search, so for your very last sentence why user goona to click on the ugly url because google showing it or if I or Someone else click or give it back link on other site then how to redirect the ugly url to my SEO friendly pattern urls?
I have not publshed any url to the site with query string url please help thannks!

Ok, somehow your links were visible to Googlebot. What you can do to remove those links from the search engine results is create an account on Google Webmasters if you have not done so already.

Go to the "Crawl" section. There you will find an option for URL parameters. You can instruct Googlebot to not index any link if finds with the parameters you indicate.

so for your very last sentence why user goona to click on the ugly url because google showing it or if I or Someone else click or give it back link on other site then how to redirect the ugly url to my SEO friendly pattern

Until you get those links out of the search results...

Just like you have a rewrite rule for the nice URL to map to the ugly URL, you would need to create a rule that does the opposite... Instead of a rewrite, it needs to be a 301 redirect. This will tell the bot that the page has moved and it should update its info about the link. However, from my experience, you still need to handle/track this within your webmasters account.

I'm not sure this is the best method and if can be useful, but I'm playing a bit with RewriteMap, once defined the map inside the vhost config file:

RewriteMap id2album txt:/tmp/idmap.txt

The contents of the file are:

123 jazz
301 summer

And the rules are:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteRule ^(.*)/album/(.*)$ /watch_album.php?id=$1&video_url=$2? [L]

RewriteCond %{QUERY_STRING} ^id=([0-9]*)&video_url=([0-9]*)$
RewriteRule ^watch_album.php$ /${id2album:%1|NOTFOUND}/album/%2? [R=301,L,NC]

</IfModule>

It seems to work fine: when accessing an url as /watch_album.php?id=123&video_url=17 Apache redirects to /jazz/album/17.

More information here: http://httpd.apache.org/docs/current/rewrite/rewritemap.html

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.