Welcome to WebmasterWorld Guest from 18.104.22.168
Forum Moderators: bakedjake
As I understand it, I use the following coding to temporarily redirect all pages in a folder to a specific page:
RedirectTemp /folder/.* [mysite.org...]
Is this correct? Or do I need to do a RedirectMatch to get all pages in my folder redirected to a specific page?
Thanks in advance for the assist!
RedirectTemp [httpd.apache.org] /nick [ac.com...]
will redirect all requests for /nick/anything to [ac.com...] So whatever part of the URL path that is to the right of a successfully prefix match is appended to the new URI. So the above RedirectTemp [httpd.apache.org] directive could be written as
RedirectMatch [httpd.apache.org] /nick(.*)$ [ac.com...]
To redirect to a single URI use RedirectMatch [httpd.apache.org].
RedirectMatch [httpd.apache.org] temp /folder/ [mysite.org...]
If I want to redirect all requests for documents in a specific folder to a particular file in that folder, I should put the following in my htaccess file:
RedirectMatch /folder(.*)$ [mysite.org...]
Is that correct?
RedirectMatch [httpd.apache.org] ^/folder [mysite.org...]
will do the job quite nicely.
This directive [RedirectMatch [httpd.apache.org]] is equivalent to Redirect [httpd.apache.org], but makes use of standard regular expressions, instead of simple prefix matching.
From the description of RedirectMatch [httpd.apache.org], my emphasis.
I put this into the htaccess file:
RedirectMatch ^/folder [mysite.org...]
and received the following error:Redirection limit for this URL exceeded. Unable to load the requested page.
I also tried it without the "^" and still got the same error. The big problem now is that I can't access the index page for that folder at all. I keep getting the same error.
Just look at what is happening. A request comes in to /folder/something. This request gets redirected to /folder/index.html. The UA request that URL and the /RewriteMatch/ directive matches again. The request gets redirected and this goes on until it exceeds the redirection limit for the URL.
You could redirect to a URI that will not match the RE again. If that is not an option then using mod_alias will be quite hard.
I believe there is no negative lookahead assertation in POSIX standard regular expressions so you probably can´t do something like this:
RedirectMatch [httpd.apache.org] ^/folder(?!/index.htm) [domain.tld...]
This would match "/folder" not followed by "/index.htm" anchored at the start of the URL path.
To overcome this limitation you might be able to do this.
RedirectMatch [httpd.apache.org] ^/folder/[^i][^n][^d][^e][^x] [domain.tld...]
This would match "/folder" followed by a character that is not "/" followed by a character that is not "i" and so on. The only limitation will be that the URI path needs to be at least 5 characters long for the rule to match.
Using mod_rewrite would solve this problem. Using a RewriteCond [httpd.apache.org] directive you´d test that the REQUEST_URI is not /folder/index.htm and use a /ReqriteRule/ to cause an external redirect to /folder/index.htm when /folder/anything gets requested.
You are a gentleman, a scholar, and a fine judge of bum whiskey. :)
RedirectMatch ^/folder/[^i][^n][^d][^e][^x] [domain.tld...]
I'm sooooo glad I didn't have to try to figure out mod_rewrite. I'm having trouble enough making sense out of mod_alias, and that seems so much easier.
I hope you do understand the limits of this approach. Although it is ok to use it if it works.
An just for the record: Using negative character classes the way I did is not a real workaround for a real negative lookahead assertation. It does not check for "folder" not followed by "index" which would match "folder" followed by "ind" or "inde". Instead it check for folder not followed by five characters where the first one is not i, the second one not n, and so on.
Fortunately, this is only needed as a temporary fix, albeit a slightly long-term one (6 months or so). Maybe before then I can figure out the whole mod_rewrite thing and put up a better solution in case this whole thing gets dragged out longer than expected. ;)
Thanks again! :)