Forum Moderators: phranque
I hope someone more knowledgeable than me can shine some light on why these rewrite rules work in my httpd-vhosts.conf but NOT in my local .htaccess file. I've taken the advice to remove the leading slash from the rules when in htaccess but this seems to break things further (error logs: "Request exceeded the limit of 10 internal redirects due to probable configuration error....")
All is well in my conf file but I'm gonna have no idea how to move these into htaccess when it comes to putting them up on live. Thanks in advance for any help...
Options +FollowSymlinks
DirectoryIndex index.php index.html
RewriteEngine On
RewriteRule^/manager/$/admin/[L]
RewriteRule^/manager/([0-9a-z_\-\.]*)$/admin/$1[L]
RewriteRule^/FCKeditor/(.*)/FCKeditor/$1[NC,L]
RewriteRule^/ajax/(.*)$/ajax/$1[L]
RewriteRule^/images/(.*)$/images/$1[L]
RewriteRule^/css/(.*)$/css/$1[L]
RewriteRule^/js/(.*)$/js/$1[L]
RewriteRule^/errors/(.*)$/errors/$1[L]
RewriteRule^([0-9a-zA-Z\-\/]*.html)$/index.php?loc=$1 [NC,L]
RewriteRule^([0-9a-zA-Z\-\/]*)/$ /index.php?loc=$1 [NC,L]
RewriteRule^([0-9a-zA-Z\-\/]*)$ /index.php?loc=$1 [NC,L]
I don't know if it's worth noting that this is on XAMPP on Windows XP, if that'd make any difference.
Current (in httpd.conf):
RewriteRule^/ajax/(.*)$/ajax/$1[L] Correct missing spaces (for httpd.conf):
RewriteRule ^/ajax/(.*)$ /ajax/$1 [L] Correct URL-paths (for .htaccess)
RewriteRule ^ajax/(.*)$ ajax/$1 [L] Remaining problem:
example.com/ajax/<anything> will be rewritten to itself repeatedly, since this rule's pattern matches the output of this rule. This will continue until the server reaches its internal redirection limit, as your error log shows.
Solution:
Unknown. The rule's purpose is not stated. This rule does nothing except create an infinite loop, since it does not change the URL-path. It could just as well be deleted.
Please give us some information about what you're hoping to accomplish with such a rule, so perhaps we can offer more useful advice.
Jim
[edited by: jdMorgan at 12:40 pm (utc) on Aug. 3, 2007]
It's worth noting that the copy-and-paste seems to have removed the spaces between the match and [i]rewrite to[i] URLs. The purpose of these rewrites are for a little CMS that I've written, which uses dynamically assigned URLs for improved indexing. The first set of rules, such as
RewriteRule^/ajax/(.*)$ /ajax/$1[L]
...is intended to make sure the 'special' directories (images, css, ajax, etc) are rewritten to their normal directories on the disk (i.e. to sort of circumvent rewriting of the last three rules). These rules, from...
RewriteRule^([0-9a-zA-Z\-\/]*.html)$/index.php?loc=$1 [NC,L]
...onwards are used to take the dynamically generated URLs for content rendering. These may contain letters, numbers, hyphens and may be in /directory/ or file (/directory/foo.html) format, hence the 'catch all' three rules.
Thanks again
If they were US-ASCII or UTF-8 spaces, though, that wouldn't happen. Make sure you are using a plain-text editor to create this file.
All I can offer without further information on failing URLs is a clean-up:
RewriteRule ^manager/[0-9a-z._\-]*$ - [L]
RewriteRule ^FCKeditor/ - [NC,L]
RewriteRule ^ajax/ - [L]
RewriteRule ^images/ - [L]
RewriteRule ^css/ - [L]
RewriteRule ^js/ - [L]
RewriteRule ^errors/ - [L]
RewriteRule ^([0-9a-z/\-]+.html)$ /index.php?loc=$1 [NC,L]
RewriteRule ^([0-9a-z/\-]+)/?$ /index.php?loc=$1 [NC,L]
For use in .htaccess, the first seven rules can be replaced by this faster alternative:
RewriteRule ^(manager/[0-9a-z._\-]*$¦FCKeditor/¦ajax/¦images/¦css/¦js/¦errors/) - [L] Note that separate rules will be faster in httpd.conf, due to the fact that it's pre-compiled instead of being interpreted at run-time as in .htaccess. Using the local OR is faster in .htaccess, though.
Replace all broken pipe "¦" characters with solid pipe characters before use; Posting on this forum modifies the pipe characters.
In order to find the looping problem, see your server error file, and find the URL-path and/or the file-path associated with the looping request.
Jim