Forum Moderators: phranque
I need help to fix my permalinks' problem. When I first started blogging, I didn't know that changing permalinks could cause problems with Search Engines. I changed from one to another just like that from my WordPress blog . In the past, I had
/%year%/%monthnum%/%day%/%postname%/ and %postname%
At the moment, I use permalink /%year%/%monthnum%/%postname%/ I note from my logs that my old permalinks have redirect 302 to the current one. Then I used a plugin to redirect 301. I also put code in .htaccess, because the plugin doesn't work without it.
RewriteEngine On
RewriteBase /
RewriteRule ^([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/([^/]+)/?$ [mysite.com...] [R=301,L]
I had some "success" with redirect 301 from my old permalink
/%year%/%monthnum%/%day%/%postname%/ to /%year%/%monthnum%/%postname%/
But the redirection from %postname% to /%year%/%monthnum%/%postname%/ gives my pages error 404. like about page and others (I have two pages)
I tried to redirect all old permalinks %postname% to /%year%/%monthnum%/%postname%/ one by one, by adding code like this in .htaccess:
Redirect 301 /mypost/ [mysite.com...]
This makes my .htaccess file size bigger. I like to keep it small and still use the permalink /%year%/%monthnum%/%postname%/
because that's what Google already indexes.
What is the best solution for this ? Should I redirect again all permalinks to %postname% ? to avoid page error 404 ? If I do that, how will it affect Seach Engines ? I'm worried Google will put me in the sandbox because I keep changing all the time. Thanks.
I tried to redirect all old permalinks %postname% to /%year%/%monthnum%/%postname%/ one by one, by adding code like this in .htaccess:
Redirect 301 /mypost/ [mysite.com...]
Just be sure that all "old" URL formats are redirected straight to the "new" URL format with a single redirect.
Don't worry too much about your .htaccess file size until it exceeds several hundred or even several thousand lines...
Also, if there are only a few "old" URLs, ask yourself how important they will be in three years when your site is four times its current size and has twice as many inbound links. If the answer is "not very important" then it might be better to let the old URLs go 404 -- certainly better than changing your URLs all the time! You may want to be selective about these old URLs, and redirect only the most important ones.
Also, depending on what other redirects and rewriterules you've got in your .htaccess file, you'd likely be better off not mixing mod_alias (Redirect and RedirectMatch) directives with mod_rewrite (RewriteCond and RewriteRule) directives, instead using only mod_rewrite. This helps assure that the directives are always processed in the expected order, and that a change of hosts or server configuration or version won't suddenly 'break' your site. So, using your example above, you'd use
RewriteRule ^mypost/$ http://www.mysite.com/2007/10/mypost/ [R=301,L]
Jim
I tried to redirect all old permalinks %postname% to /%year%/%monthnum%/%postname%/ one by one, by adding code like this in .htaccess:
Redirect 301 /mypost/ [mysite.com...]
What I meant is I had so many urls to redirect from "/%postname%/" to %postname% to /%year%/%monthnum%/%postname%/ and I did them one by one with codes like:
Redirect 301 /title 1/ [mysite.com...] 1/
Redirect 301 /title 2/ [mysite.com...] 2/
Redirect 301 /title 3/ [mysite.com...] 3/
And so on...many of those. You said "Just be sure that all "old" URL formats are redirected straight to the "new" URL format with a single redirect"
I don't understand about that RewriteRule ^mypost/$ [mysite.com...] [R=301,L]
Should I use something like:
RewriteRule ^title 1/$ [mysite.com...] 1/ [R=301,L]
RewriteRule ^title 2/$ [mysite.com...] 2/ [R=301,L]
RewriteRule ^title 3/$ [mysite.com...] 3/ [R=301,L]
What I like to do is to redirect all my "/%postname%/" to [mysite.com...]
I try to do it one by one like that to avoid 404 error in the pages about me and other pages.
Sorry if I've confused you.
Most properly-configured Web sites hosted on name-based virtual servers (shared hosting) will use mod_rewrite to address domain and URL canonicalization problems, and this is why I suggested using RewriteRule instead of Redirect. For example, most Webmasters concerned with search engine ranking will want to redirect their non-www domain to their www subdomain (or vice-versa) for best search ranking, and this requires the use of mod_rewrite.
Your RewriteRules look correct, assuming that the 'real' URLs do not have spaces in them. If there are literal spaces in the URLs, then they will have to be escaped by preceding them with a backslash, e.g. "title\ 1".
If you have no other working rewriterules, then you will need either the second of these 'setup' directives or both of them at the top of your rewriterule list:
Options +FollowSymLinks -MultiViews
RewriteEngine on
Jim