Forum Moderators: phranque

Message Too Old, No Replies

Redirect visitors coming from search engines

rewriting rule to keep good page rank

         

Blogstory

2:58 am on Apr 15, 2008 (gmt 0)

10+ Year Member



Hi all,

I have a weblog that I recently change my url format from Query String to Path Info in my CMS. It is working great.

My problem is in the requested URLs of my visitors.
They found the old url form in the Google index but the link apprear broken for them.

My old urls are indexed like this:

www.exemple.com/blog/?2008/04/13/739-my-post-title

And my new urls are like that:

www.example.com/blog/2008/04/13/739-my-post-title

I have try many rewritting rules without succes.
Can you help me starting something good and I will post my entire .htaccess to show you. I know that I need a permanent redirect so Google will index the new URL for good.

Tanks
Frank

jdMorgan

3:50 am on Apr 15, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> ... I will post my entire .htaccess to show you.

Please just post your best effort at rewriting these URLs, not your whole file! (Thanks)

This problem requires the use of mod_rewrite [httpd.apache.org], and a RewriteCond to check the value of %{QUERY_STRING}.

Jim

Blogstory

4:40 pm on Apr 15, 2008 (gmt 0)

10+ Year Member



Hi Jd,

For your info here is my old and new url format.
old: [exemple.com...]
new: [exemple.com...]

The last part (simplify url) is working great but not the two first.
I think they have been writen to remove the year/month/day from the url.
Here is my first work on this:

RewriteEngine On

# old URLs
RewriteCond %{QUERY_STRING} ^([0-9]{4})/([0-9]{2})/([0-9]{2})/([0-9]{2,3})-([a-zA-Z0-9-]+)$
RewriteRule ^blog/index.php /blog/%4-%5? [L,R=301]
# old categories
RewriteCond %{QUERY_STRING} ^([A-Z][a-zA-Z0-9-]+)$
RewriteRule ^blog/index.php /blog/%1? [L,R=301]

# simplify URL (remove index.php from url)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /blog/index.php

jdMorgan

3:07 am on May 3, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There's no example for the category URLs, but if you want to retain the date info, the old->new should probably be:

# old URLs
RewriteCond %{QUERY_STRING} ^([0-9]{4})/([0-9]{2})/([0-9]{2})/([0-9]{2,3})-([a-zA-Z0-9-]+)$
RewriteRule ^blog/index.php /blog/%1/%2/%3/%4-%5? [L,R=301]

Jim

Blogstory

2:07 pm on May 3, 2008 (gmt 0)

10+ Year Member



Hi Jim,

Your rule doesn't remove the question mark from my old indexed URL.
All external request from old URLs are redirected to the main page of my blog for now.

Any idea?

jdMorgan

2:20 pm on May 3, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If it didn't work, then either you did not completely flush your browser cache before testing, or you have a bad install of mod_rewrite. The question mark at the end of "/blog/%1/%2/%3/%4-%5?" tells mod_rewrite to clear the query string.

Jim

Blogstory

2:27 pm on May 3, 2008 (gmt 0)

10+ Year Member



I cannot change anything to the install of mod_rewrite because I use 1and1 usa for my hosting...

I use IE7 to do my test and I deleted everyting using "delete all" in the delete browsing history of the program each time I changed something to my .htaccess.

Blogstory

2:34 pm on May 3, 2008 (gmt 0)

10+ Year Member



Here is my complete .htaccess for my blog directory. The other .htacces is at the root of my domain.

RewriteEngine On
# old URLs
RewriteCond %{QUERY_STRING} ^([0-9]{4})/([0-9]{2})/([0-9]{2})/([0-9]{2,3})-([a-zA-Z0-9-]+)$
RewriteRule ^blog/index.php /blog/%1/%2/%3/%4-%5? [L,R=301]
# htaccess of blog directory for nice url without index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /blog/index.php
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?exemple.com/blog [NC]
RewriteRule \.(png¦PNG¦gif¦GIF¦jpg¦JPG¦bmp¦BMP¦wav¦mp3¦wmv¦avi¦mpeg)$ - [NC,F,L]

jdMorgan

3:54 pm on May 3, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sorry, if it does not work on your server, then it does not work on your server. The code will redirect and clear the query string on a normal mod_rewrite install.

The only other useful thing I can say is that your rules are in the wrong order and contain several inefficiencies that could be cleaned up. But this will not affect your problem.


RewriteEngine on
#
# Externally redirect old URLs
RewriteCond %{QUERY_STRING} ^([0-9]{4})/([0-9]{2})/([0-9]{2})/([0-9]{2,3})-([a-zA-Z0-9-]+)$
RewriteRule ^blog/index.php http://www.example.com/blog/%1/%2/%3/%4-%5? [R=301,L]
#
# Discourage hotlinking
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?example.com/blog [NC]
RewriteRule \.(png¦gif¦jpg¦bmp¦wav¦mp3¦wmv¦avi¦mpeg)$ - [NC,F]
#
# Internally rewrite all URLs which do not resolve to existing files or directories to /blog/index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /blog/index.php

Jim

Blogstory

7:54 pm on May 3, 2008 (gmt 0)

10+ Year Member



Big thanks Jim,

I can only add this info to my problem...

My CMS (dotclear) is suppose to create Url like the one bellow when we use the Query String format:
http://www.example.com/blog/index.php?yyyy/mm/dd/id-title

I wrote 700 entries using a url format without index.php in Query String:
http://www.example.com/blog/?yyyy/mm/dd/id-title

I have made the error of never put the "index.php" in the blog URL settings of my CMS. I think this is creating a bad form of url.