RSS Forums RSS
Please support our IT Professionals' Lounge advertiser: Programming Forums

Help with htaccess

Join Date: Jul 2006
Location: Deptford, London
Posts: 971
Reputation: MattEvans has a spectacular aura about MattEvans has a spectacular aura about 
Rep Power: 5
Solved Threads: 48
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is offline Offline
Posting Shark

Re: Help with htaccess

  #3  
Mar 15th, 2007
If you check your Apache errorlog file when running the code you want (i.e. the same, without the / or with a /?) ; then you'll see a line like this:

Originally Posted by Apache
[Fri Mar 16 00:54:31 2007] [error] [client 127.0.0.1] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace., referer: http://127.0.0.1/whatever

Simply; if you run a redirect for (.*); it will match for every request; including the internal requests for index.php. I didn't use "LogLevel debug" as that error message suggests; but it will do something like:
request: /something
redirect 1: /index.php/something
redirect 2: /index.php/index.php/something
redirect 3: /index.php/index.php/index.php/something
etc; until it reaches the"LimitInternalRecursion" setting.

There's probably more than one way to prevent this; but, here is a way:

Options +Indexes +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^\/index\.php(.*)$
RewriteRule ^(.*)$ index.php/$1 [QSA,L]

The RewriteCond line prevents any redirects where the request URI begins with /index.php. REQUEST_URI (URI not URL) is a server environment variable, and its set fresh for every request, to the path from the document root to the requested 'file'. it's important that you take the preceding slash into account.

The RewriteRule is pretty much the same as you had; except it doesn't need a '/' and it uses the QueryStringAppend flag; (means you should be able to silently pass QueryString variables into the redirected request; but, it might not be neccessary; that depends entirely on how Apache handles internal redirection.)

Like I say, there could be other ways; I been messing around for the past half hour trying to find a cleaner solution; but, thought I'd share this with you for the time being..
Last edited by MattEvans : Mar 15th, 2007 at 10:30 pm. Reason: capitalizing URI to make it look less like URL
Plato forgot the nullahedron..
Reply With Quote  
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 1:20 pm.
Newsletter Archive - Sitemap - Privacy Statement - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC