Forum Moderators: phranque

Message Too Old, No Replies

Permalink problem

Too many Permalinks structure

         

Reni

12:34 pm on Jul 8, 2009 (gmt 0)

10+ Year Member



Dear Webmaster world,

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.

jdMorgan

1:31 pm on Jul 8, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



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 should have worked, assuming that "mypost" is the same as "/%postname%/" -- The use of "mypost" and "/%postname%/" in your example above seems inconsistent) and that there are no 'special characters' in postnames.

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]

and be sure to escape all characters that have meaning in regular expressions patterns by preceding them with a "\". These characters will require escaping: $ % ^ * ( ) + { } [ ] ¦ " . ? \ and space

Jim

Reni

11:35 am on Jul 12, 2009 (gmt 0)

10+ Year Member



Mr. Jim Thankyou very much for your help, I'm very sorry for replying so late. but I think I gave you some wrong examples about :

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.

jdMorgan

6:28 pm on Jul 12, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As I said above, if you have other RewriteRule directives in your file, then do not mix "Redirect" and "RewriteRule" directives. These two directives are handled by two different Apache modules (mod_alias and mod_rewrite), and therefore you will not have control over their order of execution if you mix them -- The execution order will be determined by your server configuration, and may change if your host modifies the server configuration or "upgrades" your server (or if you change hosts), causing unexpected and incorrect operation.

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

The first line may not be needed, and/or it may not be allowed on your server. The only way to find out is to test. If it is required and not present, or if it is present but not allowed, then you'll get a 500-Server Error. The second line is always required in order to enable mod_rewrite processing.

Jim