Need help with mod_rewrite rule

Hi guy,

I have problems with setting Yii in virtual host.

I can’t go to any link from the home page. In error log it said

Since I can’t modify the rule of the host I can only fix it in .htaccess.

Request exceeded the limit of 10 internal redirects due to probable configuration error

Here are my config file for virtual host in apache2.conf




<VirtualHost *:80>

	UseCanonicalName Off

	VirtualDocumentRoot /data/www/vhosts/%0/htdocs/

	CustomLog /data/logs/wildcard-access_log combined

	ErrorLog /data/logs/wildcard-error_log

	<Directory /data/www/vhosts/>

		AllowOverride All

		Options -Indexes -FollowSymLinks -MultiViews

		Deny from all

		Allow from 192.168.0 192.168.1 192.168.2 192.168.3

		AuthType Basic

		AuthName "Top Secret"

		AuthUserFile /data/www/vhosts/.htpasswd

		require valid-user

		Satisfy any

	</Directory>

</VirtualHost>



And here is my .htaccess




Options +FollowSymLinks

IndexIgnore */*

RewriteEngine on


# if a directory or a file exists, use it directly

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d


# otherwise forward it to index.php

RewriteRule . index.php



Yes it’s default. It is located in :-

/data/www/vhosts/www.example.com/htdocs

(www.example.com is for example)

My mian.php in config is… (show only URL part)




        'urlManager' => array(

            'urlFormat' => 'path',

            'showScriptName' => false,

            'rules' => array(

                  'somerule' => 'something'

            ),

        )



Do anyone have anyone ideas?

Thanks in advance,

Just googled this error and found this link - http://www.webmasterworld.com/forum92/5628.htm

Thanks,

From that I investigated more so I found…

The rewrite loops from ../htdocs/index.php to ../htdocs/index.php so that’s why it said Request exceeded the limit of 10 internal redirects due to probable configuration error

That’s what I know about it but how to solve still a myth :(

The only hope is mod_rewrite configuration… I’m not expert for this kind of things.

This rule is not correct. The correct rule is:




RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^(.*)$ index.php/$1 [L]



Oops, sorry, just checked the docs again, your rule is correct. But maybe give my alternative a try.

Hi Mike,

I’ve just tried it but unfortunately it didn’t work.

Anyway thanks for that if I can try something that means we’re close to the solution.

And when I looked at the error log of my server I found this.




[Mon Oct 25 06:40:52 2010] [error] [client 192.168.1.225] 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://www.myexample.com/

[Mon Oct 25 06:40:52 2010] [debug] core.c(3063): [client 192.168.1.225] r->uri = /htdocs/index.php/htdocs/index.php/htdocs/index.php/htdocs/index.php/htdocs/index.php/htdocs/index.php/htdocs/index.php/htdocs/index.php/htdocs/index.php/htdocs/index.php/products, referer: http://www.myexample.com/

[Mon Oct 25 06:40:52 2010] [debug] core.c(3069): [client 192.168.1.225] redirected from r->uri = /htdocs/index.php/htdocs/index.php/htdocs/index.php/htdocs/index.php/htdocs/index.php/htdocs/index.php/htdocs/index.php/htdocs/index.php/htdocs/index.php/product, referer: http://www.myexample.com/

[Mon Oct 25 06:40:52 2010] [debug] core.c(3069): [client 192.168.1.225] redirected from r->uri = /htdocs/index.php/htdocs/index.php/htdocs/index.php/htdocs/index.php/htdocs/index.php/htdocs/index.php/htdocs/index.php/htdocs/index.php/product, referer: http://www.myexample.com/

[Mon Oct 25 06:40:52 2010] [debug] core.c(3069): [client 192.168.1.225] redirected from r->uri = /htdocs/index.php/htdocs/index.php/htdocs/index.php/htdocs/index.php/htdocs/index.php/htdocs/index.php/htdocs/index.php/product, referer: http://www.myexample.com/

[Mon Oct 25 06:40:52 2010] [debug] core.c(3069): [client 192.168.1.225] redirected from r->uri = /htdocs/index.php/htdocs/index.php/htdocs/index.php/htdocs/index.php/htdocs/index.php/htdocs/index.php/product, referer: http://www.myexample.com/

[Mon Oct 25 06:40:52 2010] [debug] core.c(3069): [client 192.168.1.225] redirected from r->uri = /htdocs/index.php/htdocs/index.php/htdocs/index.php/htdocs/index.php/htdocs/index.php/product, referer: http://www.myexample.com/

[Mon Oct 25 06:40:52 2010] [debug] core.c(3069): [client 192.168.1.225] redirected from r->uri = /htdocs/index.php/htdocs/index.php/htdocs/index.php/htdocs/index.php/product, referer: http://www.myexample.com/

[Mon Oct 25 06:40:52 2010] [debug] core.c(3069): [client 192.168.1.225] redirected from r->uri = /htdocs/index.php/htdocs/index.php/htdocs/index.php/product, referer: http://www.myexample.com/

[Mon Oct 25 06:40:52 2010] [debug] core.c(3069): [client 192.168.1.225] redirected from r->uri = /htdocs/index.php/htdocs/index.php/product, referer: http://www.myexample.com/

[Mon Oct 25 06:40:52 2010] [debug] core.c(3069): [client 192.168.1.225] redirected from r->uri = /htdocs/index.php/product, referer: http://www.myexample.com/

[Mon Oct 25 06:40:52 2010] [debug] core.c(3069): [client 192.168.1.225] redirected from r->uri = /product, referer: http://www.myexample.com/

[Mon Oct 25 06:40:52 2010] [debug] mod_deflate.c(615): [client 192.168.1.225] Zlib: Compressed 604 to 366 : URL /htdocs/index.php/htdocs/index.php/htdocs/index.php/htdocs/index.php/htdocs/index.php/htdocs/index.php/htdocs/index.php/htdocs/index.php/htdocs/index.php/htdocs/index.php/product, referer: http://www.myexample.com/



My Yii app is installed at www.myexample.com.

And I tried to reach www.myexample.com/product.

If anyone has any clues, I’ll thank you very much.

You did, what i would do, too: Check the logs to see what’s happening. My next step would be: Try another server, where it works and compare the output. And maybe increase the log level for mod_rewrite.

Let us know, what you find out.

I modified this rule a bit and that helped :)

RewriteRule ^([^/].*)$ /index.php/$1 [L]

The idea is to add slash in the beginning so that the rule will not match after rewrite completed.