Forum Moderators: phranque
example of what I want to do:
example.com/folder1/anypage.html =>301 to => example.com/newblog/
example.com/folder2/anypage.html =>301 to => example.com/newblog/
I'm hoping there's a simple way. I've done page to page redirects before but this is more complex to me.
Thanks,
Jim
This directive makes the client know that the Redirect is permanent (status 301). Exactly equivalent to Redirect permanent.
RedirectMatch uses Regular Expressions, the Redirect directive doesn't.
RedirectMatchThis directive is equivalent to Redirect, but makes use of standard regular expressions, instead of simple prefix matching. The supplied regular expression is matched against the URL-path, and if it matches, the server will substitute any parenthesized matches into the given string and use it as a filename.
Redirect (and its RedirectPermanent and other flavors) uses prefix-matching. If the specified URL-prefix matches the client-requested URL-path, then any part of the client-requested URL-path that was NOT specified in the Redirect prefix gets appended to the specified new URL prefix.
So this would defeat what you are trying to accomplish, because it would NOT drop the old post names -- It would carry them over.
RedirectMatch, however, does not use prefix-match, it uses regular-expressions pattern-matching, which is much more powerful and allows matches anywhere in the URL-string, not just in the prefix. It also requires that any part of the URL-path to be "copied-over" from the requested URL to the new URL be explicitly stated by using back-references to parenthesized sub-patterns -- $1 through $9, for example, would back-reference the values matching the first through ninth parenthesized sub-patterns.
If this is all Greek, then we'd be pleased to answer your questions about what resources to use to translate it, and perhaps offer advice on the most idiomatic translation for a particular phrase. However, we're not set up to follow you around on your tour and do all the talking for you... That is why we always ask that any thread requesting code include a 'best-effort' attempt. It saves time by letting everyone know what the poster does and does not already grasp, and where the 'tutoring' should be focused.
Reading the Apache documentation is a really good use of your time if you want to run a well-mannered server hosting a well-ranked site... :) It's not easy, reading all that. But it is a lot easier than recovering a site that lost its search ranking because of one little error in the server config code. And that is not an unlikely scenario, it happens all the time.
"Rewrite on" is neither valid nor required. "RewriteEngine on" is a directive for mod_rewrite, which we are not using here (though we could).
RedirectMatch ^/folder1/[^.]+\.html$ http://www.example.com/newblog/
RedirectMatch ^/folder2/[^.]+\.html$ http://www.example.com/newblog/
Having worked through that example, you could combine those two directives:
RedirectMatch ^/(folder1¦folder2)/[^.]+\.html$ http://www.example.com/newblog/
Jim
I'll give that code a try, then see if I need further help with it. I will be trying the 2 line version as my folder2 has files ending with ".cgi" instead of ".html".
Sorry to be delayed getting back to this but I had to sleep. Working the graveyard shift makes for strange hours.
The Apache section of the WebmasterWorld library contains links to several useful threads as well.
Look in the technical section of on-line booksellers sites -- There are a decent number of books on Apache and on regular expressions on the market. WIth a list of these, you can go to your local bookstore and see which ones are wrriten in a style that best fits with your preferred way of learning.
Jim
Use RedirectMatch 301 ....
Jim