Forum Moderators: phranque
However before we get started, some questions:
Have you physically moved some files from one folder to another?
Having moved some files around inside the server, are you aware that you could still use the old URLs to access those files if you wanted to, by using a rewrite?
That is, is a redirect actually necessary?
Is this a similar issue? [webmasterworld.com...]
www.domain.com/12345.html (current server) to
www.domain.com/folder/12345.html (new server)
With these changes I want to let the search engines know of my change, usually done by htaccess 301 redirects. There are thousands of files and need some sort wildcard solution.
Thanks for your help...
So what g1smd is telling you is that moving files around inside a server *does not* always require the URL to be changed, and that you can move the files to a subfolder and simply rewrite requests for their previous URLs to the new fiepath. Note: A URL is not a filepath -- They are only "associated" things.
In this case it might be a simple matter to internally rewrite requests for any URL like /<numbers>.html to the filepath /folder/<numbers>.html, and leave the URLs alone.
If your new server has a different domain, then it would also be fairly simple to redirect from the old server's domain to the new while retaining the original URL-path, and then rewrite those original URL-paths to the new filepath inside the new server. However, much of the SEO value of retaining old URLs will be lost if you change domains as well as servers.
If you decide to proceed with external redirection rather than internal rewriting, we have lots of previous threads here on redirecting to a subfolder while avoiding 'infinite' redirection loops -- Try the site search link at the top of this page. This is also a trivial redirect, and the examples in the Apache mod_rewrite --or mod_alias-- documentation should be sufficient to get you started.
This all may seem pedantic, but it does you no good if we give you perfectly-good technical redirect advice but don't mention that your site will take a hit in search ranking... temporarily, at least.
Jim
If you ask for the URL example.com/something.htm the server will try to get content from /folder/something.htm
Problem is, with /folder/something.htm this now matches the rule again, and the server will try to get content from /folder/folder/something.htm - but this now also matches the rule again.
So, you need to add [L] to the end of your rule. You also need a better pattern that does not keep matching recursively. Currently it matches "not a period". I would change [^.] to [^./] instead.
If you want a redirect (instead of a rewrite), you need to also add the domain name and [R=301,L] to the target. A redirect forces the browser to request a new URL
Is that what you want. Be aware there are at least three other threads active yesterday and today covering the same ground.
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /folder/[^.]+\.htm\ HTTP/
RewriteCond ^folder/([^.]+\.htm)$ http://www.example.com/$1 [R=301,L]
Jim