301 versus inline rewrites - php

I'm in the process of adding 'pretty' URLs to an existing CMS, the menu is auto generated and the new 'pretty' URLs are to be handled independently as a seperate module. The auto-generated menu allways has URLs that look like this index.php?menu_id=n which ofcourse we would like to see as eg. /news or /products
I'm currently at the point where I have to decide if I'm going to rewrite all output of the current system or simply put in a hook where I redirect to the 'pretty' URL.
To put it differently, should i connect to the database, fetch all 'pretty' URLs, run through the existing output from WYSIWYG's, news modules, forums etc. and do some str_replace or other string manipulation (which I think would be a rather tedious and boring process), or should I simply hook in and throw a 301 redirecting index.php?menu_id=3 to /news will Google (or other search engines) penalize me for having 301's in the menus?

301 is a permanent redirect, and search engines understand them. They don't penalize you for a 301.
My recommendation - a combination of both. For pages in your control, modify the urls. For ones beyond your control (third party blogs, other websites etc) and for your own pages that are difficult, 301s should be fine.
There is a performance aspect to 301s as well, so avoid them when you can. But if you don't have a choice, its okay.

A 301 redirect is competely the correct behaviour in this instance because the resource has 'moved', and Google should not penalise you at all.

I would recommend attempting to replace as many as you can using a simple clean-up process. I faced the same issue and solved the problem by...
1) Detecting requests to the old URL and issuing a 301 redirect (useful especially for external links to the page)
2) Any auto-generated URLs such as the menu were updated as the code changed to generate the friendly URL
3) For WYSIWYG I performed a clean up once across all of the content to replace old URLs with the new friendly URLs, which meant less redirects being sent to the client and no "old" style URLs being displayed in status bars.

of course you have to rewrite output system.
or there will be no point in URL rewriting at all

Related

Doing a redirect without using 301 but a PHP script, is that OK?

I've been reading about redirection, and how it can affect (or not if done properly) SEO.
I'm changing my website's content platform from Drupal to a PHP custom made code.
In my current site I have two links that point to the same link like this:
.../node/123
.../my-node-title
Mainly because Drupal allows you to create a custom-made links, so every article has a default one (node/123) and the custom-made one (/my-node-title).
My question is about what to do in order to prevent losing any SEO that each link may have.
In the new website all articles are structured like this: content.php?id=123
I've stored in the database the custom-made link of every article.
Instead of doing a 301 redirect I'm redirecting all links that do not exist to be redirected to redirect.php page to process the request. There I take the string from the link, look for it in the database and redirect the user.
The process is like this:
in .htaccess file:
RewriteRule ^.*$ ./redirect.php
In redirect.php:
I grab the $_SERVER['REQUEST_URI'] and using explode() I get the last part of the link (ie. my-node-title), look for it in the database and grab the ID of the article (ie. 123) and save it in a $link variable.
Then I use header() function and do the redirect: header('Location: '.$link);
So, people still click on .../my-node-title but when the article loads at the navigation bar appears /content.php?id=123
I would like to know your comments about this solution. I know that with SEO there are not fixed rules, or certainty in anything, but I would like to know if what am I doing is acceptable. Thanks!
Your SEO strategy should not only focus on discoverability of your pages, but also take proper UX into account. Having a user follow /some-link/, and then landing on /index.php?page_id=123 may disorient them.
As for saving your ranking, a 302 redirect (which is what the 'Location' header does in PHP), will not affect PageRank, according to Google. I have no information on how it might adversely affect other ranking signals. You would probably do good to specify a canonical URL for all distinct links that point to the same resource.
Also, be aware that your algorithm won't work, if query parameters are present. You might also want to look at properly handling optional trailing slashes.
Ideally, in my opinion, you would want to provide consistent URLs to the outside world, without any need for redirection. Your URL handling would then internally resolve them to their respective resources, serving the canonical URL on every page load.

WordPress: Automatic 301 redirect after page deleted

I have a wordpress website with dynamic content via API. every day we have hundreds of new content pages and hundreds of old pages that been deleted automatically. Is there a solution to create a automatic 301 redirect for this pages? The goal is to avoid thousands of 404 pages after a few weeks...
1a. Decide what you'll redirect TO.
Figuring where any particular OLD/missing url should be redirected to can be as simple [generic url] or complex [pattern-matching-language-AI] as you need. At the very least, you should probably try to match up similar articles by a few fields: url, title, meta, keywords, H-tags in content.
Redirecting to one common url IS a 404, whether you tell people it's a 301 or not.
Ultimately, if you're just going to redirect them all to one page, why bother with a redirect at all? What you've just built is a 404-page that will never 404, but will have the same effect on SEO. Instead, just customize your 404 page with that content.
1b. Categorize ALL pages. Redirect the Category page.
Setting some basic requirements for how your imported content will be organized will drastically simplify your problem. If you can lump these pages into some basic standard categories (which won't change, and need not be displayed in nav anywhere), your problem is 90% solved. The last step is then to simply create some simple rewrite rules from step 2a: url matches a category and page missing? 301 to category.
2a. Learn and apply your own rules with the Rewrite API.
This is not an uncommon problem, that's why there's a tool for it built-in to WP: the Rewrite API. This lets you add your own rewrite rules (matching Requested URL to specific Responses) to WP, to let WP do the rest.
I'm not going to tell you it will be easy, but it is the best solution, if you intended on proceeding despite my advice at the end.
2b. Catch-all requests, and wp_redirect before WP loads a 404.
Warning: here be dragons
Wordpress uses .htaccess to route most requests to index.php, which itself acts as the main loader for all of WP. There are plenty of places in this process into which you could inject your own url-rewrite engine, effectively replacing wordpress for handling any of your predefined URLs. Once you're there, you can pretty much do anything with the request, but I'd suggest sticking to something simple, like wp_redirect( "http://example.com/new-page", 301 );
Please: Let your 404s be 404s, or only redirect to the page's old category.
There's a reason why this behavior is part of a well-defined standard for request/response cycles. Not just in HTTP, but this is one of 4 basic response states for ALL forms of communication responses: didn't-catch-that, my-answer, i-don't-know, choking. You ever worked with someone who never admits to themselves that they don't know something? That's what you'll be turning your site into.
Effectively, you're trying to save SEO for missing URLs, and to avoid massive amounts of 404 errors. To do it, at best you'll be directing old urls to completely unrelated content most of the time. This is effectively the same impact on SEO as showing a 404 page.
More on this at moz.com.

Changing URLs in WordPress from having month and year to not having them

At the moment I have a WordPress site which has some posts and the links for those look like this:
http://www.example.com/2015/09/some-post
I need to change those URL's to
http://www.example.com/some-post
which is easy enough but I want also to make the old links redirect to the new links automatically. Is there a way to do this with a plugin or in the .htaccess file or in some other way?
Yes, certainly you can do it either way. Via .htaccess redirect, or using a redirection plugin. Or you can use both at the same time.
However, assuming you are doing this for SEO purposes, and want to redirect previously linked URLs in order to pass any existing "link juice" to the new link, then you really should consider the plugin approach first.
The best feature of these plugins is the overall logging, mapping, and administration of your URL redirection plan. You will want to make sure all your old URLS are returning an HTTP 301 Moved Permanently response code, and not a 302 Moved Temporarily, or worse a 404. These plugins are great for this type of redirection task, and will quickly allow you to see if your old links are being redirected properly. Incorrect redirection of old links will result in loss of the link power/equity you may already have on those links.

wordpress rewrite and google SEO issue

I have a custom wordpress page that I wanted to make its url SEO friendly.
So I added some code using rewrite api to convert this url:
http://example.com/page1/?id=1234
to:
http://example.com/page2/1234
page1 is still there and first url still valid. page1 was not very descriptive so I though that since I'm rewriting the url I might as well rename the page too.
Everything on the website works fine, but when I recreated the sitmap xml file and resubmitted to google I was hoping google would forget the old url and start showing the new one. This was a few weeks ago and I'm still seeing old urls. Any idea how I can remove the old urls? Do I need to physically rename the page itself?
Please help.
Thanks
Since google has indexed old URLs, it will stay in their index unless you do something about it. There are two options you can handle.
If you want the old urls to coexist, you can do rel="canonical" on the old URL pages. Canonical will indicate that they are same pages with different urls.
Other option is doing 301 redirect. 301 indicates that the page has moved permanently and it helps search engines to carry over the SEO values of the old urls to the new ones. In due course search engines will index the new urls and old urls will go away. After a certain point in time, once you are sure that old URLs are not receiving any traffic, you can get rid of the redirect rule.

Migrating an existing PHP site to use URL re-writing (Pretty URL's)

I currently have a community site that I run that is made up of 15 or so php pages. It is not currently very dynamic, only using php for includes/templates.
Currently no content is generated via a query string. The pages do not follow a standard naming convention and there are many inbound links.
I am looking to expand the site (and start using query strings to build pages) but before I do this I want to change over to use pretty url’s. With this in mind I have a few questions though.
1) Is it best to point all requests to a url rewriting page catch any request to .php pages first and pass them through to keep existing links then a giant case statement for each of the 15 pages finally the rewrite the url's of new pages as these will follow a set format?
2) How can I prevent duplicates in google after I have updated my sitemap.xml or will it remove the old pages?
Thanks
1) I'd redirect using apache's URL rewrite, and leave that static. It'll avoid the mess of having those 15 files you already have in your site.
I hope I have not misunderstood your question and this helps.
2) Edit robots.txt in the root of your website to tell google (and most others) what it should index, and what it shouldn't:
Google's info on the subject: http://www.google.com/support/webmasters/bin/answer.py?hl=en&answer=40360
Wikipedia: http://en.wikipedia.org/wiki/Robots_exclusion_standard
More info: http://www.robotstxt.org/
You should use a 301 permanent redirect from the old pages to the new URLs. This will redirect users that follow links from the old to the new and Google will pass the PageRank you have accumulated on the old pages to the new one. You might also look at using Googles new canonical tag on the old pages to ensure they transfer authority to the new page.
http://googlewebmastercentral.blogspot.com/2009/02/specify-your-canonical.html
In .htaccess, you want a bunch of
redirect 301 /old/old.htm http://www.you.com/new.htm
Regardless how its implemented, make sure any redirects use HTTP status 301, not the default (in may systems) of 302.
302 = Moved
301 = Moved permanently.
Using 301 helps google replace the old with the new URL, and should help pagerank etc carry over as well.

Categories