Forum Moderators: phranque
I want to avoid broken links and lost traffic by redirecting users to the new folder. I'm used to using Redirect permanent but as it's so many files this time I think I should be using mod_rewrite. I already have a functioning Rewrite area in my .htaccess file to prevent hotlinking, so I just need the syntax for the extra line, but I'm not confident in it. Could someone please advise if this line would do it? (note the new directory name has a hyphen in it)
RewriteRule ^/olddirectory(.*) /new-directory$1 [R=permanent,L]
Thanks!
RewriteCond %{REMOTE_ADDR} ^111\.222\.333\.444$
RewriteRule ^/olddirectory(.*) /new-directory$1 [R=permanent,L]
[edited by: SteveWh at 8:01 pm (utc) on May 14, 2009]
Unfortunately my redirect is not working. Typically I would like URLs such as this...
http://www.example.com/olddirectory/level1/leve2/page.htm
...to be redirected to...
http://www.example.com/new-directory/level1/leve2/page.htm
There are jpeg files below the name-change directory too. The whole structure remains the same. I've just changed the directory name. But queries are still finding the old directory.
Any help would be greatly appreciated!
[edited by: jdMorgan at 3:39 pm (utc) on May 15, 2009]
[edit reason] example.com [/edit]
This is a case where it is not clear that the URL needs to be changed at all. It would be possible to simply rewrite requests for the old URL to the new filepath, without disturbing the URLs or their current search rankings at all.
With all of the URLs changing all at once, it may take several weeks to nine months to recover the previous page rankings in search.
As I said, it's not clear. It may be in fact be what is really desired or needed in this specific case. But in many if not most cases a change in the server's internal file structure does not require a change in the public URLs. An internal rewrite would suffice:
RewriteRule ^olddirectory/(.*)$ /new-directory/$1 [L]
RewriteCond %{DOCUMENT_ROOT}/newdirectory/$1 -f [OR]
RewriteCond %{DOCUMENT_ROOT}/newdirectory/$1 -d
RewriteRule ^olddirectory/(.*)$ /new-directory/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^olddirectory/(.*)$ /new-directory/$1 [L]
Hypertext Style: Cool URIs don't change. [w3.org]
Jim
Thanks to Jim for the comments about URIs possibly not needing to change. I considered hard, based on what I know about SEO etc., and in this case I decided to rename the directory for simpler management locally on my machine, and for a better logical structure as seen by users and the search engines. I'm also updating titles and descriptions as part of an overhaul.
The few pages from that directory that do well in a Google search, still point to the old directory name in the search results. I'll wait and see what happens to the SERPs when Google re-indexes. I'm hoping they won't drop, but if they do, hopefully other pages in the directory will at least make up for it with higher positions.