homepage Welcome to WebmasterWorld Guest from 54.196.207.55
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
How to stop the endless loop in .htaccess
Redirect /photo http://somedomain.com/photo/upload/index/
Iron dutchess




msg:4679851
 10:38 am on Jun 14, 2014 (gmt 0)

Hi,

I want to redirect anyone arriving at the /photo sub directory to /photo/upload/index/

Redirect /photo http://example.com/photo/upload/index/

The above just causes an endless loop as the redirect trigger and destination both contain /photo

Is there a way around this problem?

TIA
Chris

 

lucy24




msg:4679917
 7:56 pm on Jun 14, 2014 (gmt 0)

You need to exclude requests that already contain /upload/index/. This is most easily done by constraining the rule to requests for
/photo/filename.xtn
Is /index/ the name of a directory? Does it contain the files that were formerly in /photo/ alone?

You may or may not be able to do it in mod_alias (Redirect by that name, or rather RedirectMatch) depending on exactly what URLs are involved. If you need to convert to mod_rewrite, you'll also need to change all your existing redirects, because you can't combine these two mods without unintended consequences*. Happily there's a near-identical question posted within the last 48 hours

:: shuffling papers ::

[webmasterworld.com...]

In that thread, he doesn't want to capture the last bit of the request. It sounds as if you do. But the underlying principle is identical. More information, please :)


* Apache-speak for "widespread death and destruction leading to the end of civilization as we know it".

Iron dutchess




msg:4679930
 8:50 pm on Jun 14, 2014 (gmt 0)

Thanks for the reply.

/photo and /photo/upload/index aren't really folders, they are calls to sections of /index.php that create the pages on the fly from the css, a base template html file that is located elsewhere, and the contents of a MySQL database. So until called they don't exist, so don't show up in the url as a filename, all you see in the browser is /photo and /photo/upload/index/

Would it help if I posted the rest of my .htaccess file?

lucy24




msg:4679943
 11:23 pm on Jun 14, 2014 (gmt 0)

For this situation it doesn't matter if the folders physically exist; it's just a question of what the URL looks like. But if you're doing stuff with php and a database, like a hand-rolled CMS, then surely you're using mod_rewrite already? If so, all redirects have to be expressed as RewriteRule.

Either way, if the filename you want to target is just
/photo
and that's all, then you need to express the pattern as
/photo$
using a final anchor. This remains true whether you're using mod_rewrite or mod_alias (RedirectMatch, which uses Regular Expressions), and whether or not you're capturing anyting for reuse.

Iron dutchess




msg:4679963
 9:27 am on Jun 15, 2014 (gmt 0)

Many thanks for that.

Had problems getting RewriteRule to work, but RedirectMatch /photo$ http://example.com/photo/upload/index/ worked perfectly.

Thanks again for your help with this.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
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