I have the following format for the URLs in my Google site map:
Recently, to help with SEO, I decided to make the URL contain the title of the testimonial:
Through the use of mod_rewrite and a redirect page, any user who clicks on the old URL format will arrive at the new URL format. Here is my rule:
RewriteRule ^essential-oils/([0-9]+)$ login.php?tID=$1 [L]
The login.php looks to see if there is a tID being passed and, if so, looks up the name of the testimonial in the database. It then uses a meta refresh to get the user to the intended destination with the title in the URL, like this:
Everything works great. Before I change the URL format in my google sitemap, I wanted to check with the experts here to make sure that is a wise thing to do. Matt Cutts has said before that Google is fine with a few hops or redirects, and I don't think I'm doing too many. Maybe in addition to changing the format in the sitemap I should also apply a 301 redirect in my rewriteRule? Any advice would be appreciated.
Having a few hops isn't going to turn your SEO rankings. Now if you were shuffling the user through 25 different pages it might be a different story. I mean, Google does it themselves when you log into your Google account. You can actually watch the URL change 3 or 4 times and it runs through various checks.
What you're doing seems perfectly reasonable. My only suggestion would be to make sure that the jump from the old URL to the new URL via mod_rewrite is being done with a 301 redirect. This not only makes the jump more "acceptable" but it also alerts search engine spiders to update their index with your new URL.
The mod_rewrite rule, in this case, is taking the user or spider to login.php, where it then redirects again with a refresh. So if I add a 301 redirect to it, will the spiders think that login.php is new the page or are they smart enough to consider the final landing page as the the place that I'm trying to redirect to?
As long as both hops (to login.php and to the final destination) are done with a 301, the spiders will treat the final page as the real page without any sort of penalty. Most of the time they will update their index to reflect these changes right away.
Ok, good, I'm glad I checked. One final question. Is this the PHP code you would use on login.php to do a proper 301 redirect to the final page?
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://www.new-url.com" );
I'm not a PHP expert so take my advice on this one with a grain of salt, but that looks correct to me. The Location: will perform the actual redirect and the HTTP 301 should ensure that it's passing the 301 parameter in the headers. I think you've got it!
Do you have any idea why this rewriteRule works fine:
RewriteRule ^essential-oils/([0-9]+)/([a-zA-Z0-9\-]+)$ essential-oils.php?tID=$1 [L]
But this produces a 404 error?
RewriteRule ^essential-oils/([0-9]+)/([a-zA-Z0-9\-]+)$ essential-oils.php?tID=$1 [R=301,L]
The only difference is that the second one uses a 301 redirect. Very strange.
Oye, now you're definitely barking up the wrong tree. Putting me in front of regular expressions or mod_rewrite in general brings out the classic deer in headlights look. This isn't the best forum to answer that question either. I might suggest starting a new thread with your last question in the Apache forum. We have some smart cookies hanging out over there and they'd probably be able to help you out.
This topic is now archived. It is frozen and cannot be changed in any way.