Forum Moderators: phranque
Also, do you really want a redirect, or do you simply want to serve content from the files in /blog/ when URLs in root are requested?... Which URL do you want in the search results and the user's browser address bar?
Once you decide, you might want to try a search on your thread title in our WebmasterWorld site search; This topic comes up frequently.
Jim
I want URLs with blog/ in them.
Old site structure was site.com/urls. But then moved all files to site.com/blog/urls. SO we want all incoming requests with olf structure to be redirected to new structure (with blog/ in it).
I do not want both functions at the same time, I am looking how to do the opposite thing if I need it.
In the meantime I made this and it seems to work, may be very rudimentary though.
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteRule ^(.*) [site.com...] [NC]
Options +FollowSymlinks
RewriteEngine on
#
RewriteCond $1 !blog/
RewriteRule (.*) /blog/$1 [L]
Options +FollowSymlinks
RewriteEngine on
#
RewriteCond $1 !blog/
RewriteRule (.*) http://www.example.com/blog/$1 [R=301,L]
Your answer intrigued me and I hope you do not mind me following.
If I do a 301 redirect shouldn't the search ranking be preserved as this should be the only and best way of moving urls?
If I am not to change URL's and thus just serve the content from new path, wouldn't I have a problem with duplicate content? Further I am at risk of actually splitting all my rankings between what would in practice be two sites, one leaving at / and the other one at /blog/ ?
If you change the URLs, you may expect to lose your search engine rankings for a few weeks up to nine months, depending on your current PageRank/Link-popularity. I can't tell you how long it will take, because it is determined by the search engines.
This delay is the results of search engines trying to figure out that *all* of your URLs have changed. And as Sir Tim Berners-Lee (co-inventor of the hyperlink) observed, "Cool URIs don't change [w3.org]" -- Search engines (and Web users) are happiest if your URLs *never* ever change. Another way to put it is to think of Web sites as books in a library, not as newspapers for sale on the street. Most Webmasters are *far* too cavalier about changing URLs; If they were properly designed (yes, I said designed), they would not have to change.
You can internally rewrite example.com/<something> URL requests to /blog/<something> filepaths, and then, if desired, redirect *only* direct HTTP client requests for example.com/blog/<something> URLs back to example.com/<something> URLs. That code has been posted here many times.
In this scenario *all* URLs point to example.com/<something>, and all files are stored at /blog/<something> -- The filepaths used inside the server to store files simply have "/blog" added to them, and the URLs don't need to show that.
Jim
However my friend (I am doing this for a friend of mine) has already moved the site to blog/ 2 months ago and it has been indexed by Google, linked by other sites etc.
Now she installed Webmaster tools and she gets a lot of 404 errors inside - because some sites still have old links.
So I am trying to help in best way I can. Do you think that in this case 301 redirecting / to blog/ is probably best solution?