homepage Welcome to WebmasterWorld Guest from 54.211.113.223
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
Forum Library, Charter, Moderators: bakedjake

Linux, Unix, and *nix like Operating Systems Forum

    
RedirectTemp
Before I screw up the site...
Syren_Song

10+ Year Member



 
Msg#: 410 posted 5:39 pm on Feb 8, 2003 (gmt 0)

...just wanted to make sure I was setting this up properly.

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!

 

andreasfriedrich

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 410 posted 6:20 pm on Feb 8, 2003 (gmt 0)

RedirectTemp [httpd.apache.org] expects URL-path as its first parameter, not a regular expression. Requests for resources beginning with this path will be redirected to the new URL beginning with the URL given as the second parameter to RedirectTemp [httpd.apache.org].


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...]

Andreas

Syren_Song

10+ Year Member



 
Msg#: 410 posted 6:38 pm on Feb 8, 2003 (gmt 0)

If I'm understanding you correctly, andreasfriedrich, I don't need to use RedirectTemp at all.

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?

andreasfriedrich

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 410 posted 7:07 pm on Feb 8, 2003 (gmt 0)

Yes. But you do not need to anchor the pattern at the end of the URI ($) nor do you need to capture the rest of the path following "folder" ((.*)). Instead you might want to anchor the RE at the beginning of the URI path when you want to redirect only requests to [domain.tld...] but not those to [domain.tld...]


RedirectMatch [httpd.apache.org] ^/folder [mysite.org...]

will do the job quite nicely.

Andreas

Syren_Song

10+ Year Member



 
Msg#: 410 posted 10:15 pm on Feb 8, 2003 (gmt 0)

I get it now! Too bad there's no emoticon for a lightbulb going on. ;)

I knew I wasn't catching the full gist of what I needed to know from the Apache site. Thanks for setting me straight, andreasfriedrich!

andreasfriedrich

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 410 posted 10:42 pm on Feb 8, 2003 (gmt 0)

The Apache [httpd.apache.org] docs are not as clear as one might wish. Although it´s all there. Just like they teach you in Law School to read the next and previous sections of the one you are looking at reading around related directives will help a lot as well:

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.

Andreas

Syren_Song

10+ Year Member



 
Msg#: 410 posted 11:15 pm on Feb 8, 2003 (gmt 0)

Okay. The lightbulb just went out.

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.

andreasfriedrich

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 410 posted 12:18 am on Feb 9, 2003 (gmt 0)

You´ve successfully created an endless loop ;)!

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.

Andreas

Syren_Song

10+ Year Member



 
Msg#: 410 posted 3:12 am on Feb 9, 2003 (gmt 0)

andreasfriedrich -

You are a gentleman, a scholar, and a fine judge of bum whiskey. :)

RedirectMatch ^/folder/[^i][^n][^d][^e][^x] [domain.tld...]

worked beautifully!

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.

Thanks again!

andreasfriedrich

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 410 posted 12:30 pm on Feb 9, 2003 (gmt 0)

You are welcome Syren_Song.

Syren_Song [webmasterworld.com] wrote at 03:12 on Feb. 09, 2003 in message #9 [webmasterworld.com]
worked beautifully!

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.

Andreas

Syren_Song

10+ Year Member



 
Msg#: 410 posted 2:11 pm on Feb 9, 2003 (gmt 0)

That makes a lot of sense as far as the limitations are concerned.

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! :)

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved