Forum Moderators: phranque
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
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
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
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]
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
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.