Forum Moderators: phranque
I have been told the following rule could possibly causing a looping error on our site and I was just wondering the best way to correct it.
My knowledge of RewriteRules is nil so any help would be very much appreciated.
-------------------------
RewriteRule ^adverts/(.*) adverts/$1 [L,PT]
-------------------------
Cheers
Harad
Here is the entire .htaccess file. This line is to allow another program in the adverts directory to function correctly apparently. Any help or advice would be great.
Options +FollowSymLinks
Redirect 301 /testing301.php [domainname.com...]
RewriteEngine on
RewriteRule ^sitemap.xml index.php?app=$1&ns=googlesitemap [L,PT]
RewriteRule ^apc.php apc.php [L,PT]
RewriteRule ^admin.php admin.php [L,PT]
RewriteRule ^index.php index.php [L,PT]
RewriteRule ^installer.php installer.php [L,PT]
RewriteRule ^news/(.*) news/$1 [L,PT]
RewriteRule ^relay/(.*) relay/$1 [L,PT]
RewriteRule ^adverts/(.*) adverts/$1 [L,PT]
RewriteRule ^(.*)-(.*)/(.*)\.html index.php?app=$1&ns=$2&ref=$3 [L,PT]
RewriteRule ^(.*)\.php index.php?app=gbu0&ns=catprodshow&ref=$1 [L,PT]
RewriteRule ^news/(.*) news/$1 [L,PT]
rewritecond %{http_host} ^domainname.com
rewriteRule ^(.*) [domainname.com...] [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/
RewriteRule ^(.*)index\.html$ [domainname.com$1...] [R=301,L]
<FilesMatch "\.(jpg¦jpeg¦png¦gif¦swf)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
All of the rewrites need to be listed so that they are after all of the redirects.
The rewrites are the things with [L] and the redirects are the things with [R=301,L]
Add a comment to each rule block to explain what the next line does.
Options +FollowSymLinks
Redirect 301 /testing301.php [domainname.com...]
RewriteEngine on
RewriteRule ^(.*)index\.html$ [domainname.com$1...] [R=301,L]
rewriteRule ^(.*) [domainname.com...] [R=301,L]
RewriteRule ^index.php index.php [L,PT]
RewriteRule ^(.*)\.php index.php?app=gbu0&ns=catprodshow&ref=$1 [L,PT]
RewriteRule ^(.*)-(.*)/(.*)\.html index.php?app=$1&ns=$2&ref=$3 [L,PT]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/
RewriteRule ^sitemap.xml index.php?app=$1&ns=googlesitemap [L,PT]
RewriteRule ^apc.php apc.php [L,PT]
RewriteRule ^admin.php admin.php [L,PT]
RewriteRule ^installer.php installer.php [L,PT]
RewriteRule ^news/(.*) news/$1 [L,PT]
RewriteRule ^relay/(.*) relay/$1 [L,PT]
RewriteRule ^adverts/(.*) adverts/$1 [L,PT]
RewriteRule ^news/(.*) news/$1 [L,PT]
rewritecond %{http_host} ^domainname.com
<FilesMatch "\.(jpg¦jpeg¦png¦gif¦swf)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
Options +FollowSymLinks
Redirect 301 /testing301.php [domainname.com...]
RewriteEngine on
rewritecond %{http_host} ^domainname.com
rewriteRule ^(.*) [domainname.com...] [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/
RewriteRule ^(.*)index\.html$ [domainname.com$1...] [R=301,L]
RewriteRule ^(.*)-(.*)/(.*)\.html index.php?app=$1&ns=$2&ref=$3 [L,PT]
RewriteRule ^(.*)\.php index.php?app=gbu0&ns=catprodshow&ref=$1 [L,PT]
RewriteRule ^index.php index.php [L,PT]
RewriteRule ^sitemap.xml index.php?app=$1&ns=googlesitemap [L,PT]
RewriteRule ^installer.php installer.php [L,PT]
RewriteRule ^apc.php apc.php [L,PT]
RewriteRule ^admin.php admin.php [L,PT]
RewriteRule ^news/(.*) news/$1 [L,PT]
RewriteRule ^relay/(.*) relay/$1 [L,PT]
RewriteRule ^adverts/(.*) adverts/$1 [L,PT]
RewriteRule ^news/(.*) news/$1 [L,PT]
<FilesMatch "\.(jpg¦jpeg¦png¦gif¦swf)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
So, such rules are usually not useful unless you want to avoid executing a rule that follows one of these rewrite-to-self-and-quit rules.
However, in the new version of the rules, I don't see any RewriteRules following these self-rewriting rules, so I'm not sure what the point of them is.
I suspect that they were intended to avoid processing this rule for any of the subdirectories named in the self-rewriting rules:
RewriteRule ^(.*)\.php index.php?app=gbu0&ns=catprodshow&ref=$1 [L,PT]
but I cannot be sure.
For example, if "/admin.php" is requested, then DO NOT rewrite that to index.php?app=gbu0&ns=catprodshow&ref=admin
I can't be sure, though...
That rule is one that looks like it will loop, rewriting a request for x.php to /index.php?app=gbu0&ns=catprodshow&ref=x, and then rewriting that to /index.php?app=gbu0&ns=catprodshow&ref=index, and then repeatedly rewriting that URL to itself until the server's maximum internal redirection limit is reached (see your server error log).
Any rule in .htaccess that produces an output that matches its own input pattern must have a RewriteCond that excepts its own output URL-path from being rewritten. For example:
RewriteCond $1 !^index$
RewriteRule ^(.*)\.php index.php?app=gbu0&ns=catprodshow&ref=$1 [L,PT]
RewriteRule ^x/(.*)$ - [PT,L]
Basically, we can read the code and understand what it does to URLs, line-by-line. But we cannot tell what it was intended to accomplish, or what its practical effect is on your site, without fully-understanding what all those subdirectories are, where your scripts are located, and a bunch of other details.
You might want to call in a local contractor to take a few days to go over all of this with you, and make it clear that he/she won't be paid unless the resulting config file is fully-documented with clear, correct, and concise-but-complete comments preceding every line of code and every block of code... :)
Jim