Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

How to stop the endless loop in .htaccess

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


Iron dutchess

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


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?



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

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

You need to exclude requests that already contain /upload/index/. This is most easily done by constraining the rule to requests for
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 ::


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

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?


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

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

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
and that's all, then you need to express the pattern as
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

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.

Featured Threads

Hot Threads This Week

Hot Threads This Month