0

If I go to domain.com, site redirects to domain.com/en, which is expected. But then the last rule kicks in and throws it in a loop making my url look something like this:

http://domain.com/en/?lang=en&request=&site=basecamp&lang=en&request=&site=basecamp&lang=en&request=&site=basecamp&lang=en&request=&site=basecamp

.htaccess file

Options +FollowSymlinks
RewriteEngine on

RewriteBase /

RewriteCond %{REQUEST_URI} !/(content|images|css|js|fonts|pdfs)/
RewriteRule  /([^.]+\.(jpe?g|gif|bmp|png|css|js|eot|svg|ttf|ico|pdf))$ /$1 [NC,R,L]

RewriteCond %{REQUEST_URI} !(content|images|css|js|fonts|pdfs)/.*
RewriteRule !^[a-z]{2}/ /en/ [NC,L,R]

RewriteCond %{REQUEST_URI} !/(init\.php|content|images|css|js|fonts|pdfs)/
RewriteRule ^([a-z]{2})/(.*)$ init.php?lang=$1&request=$2&site=basecamp[L,QSA]

Why is the htaccess file redirecting to /?GET_VARS instead of /init.php?GET_VARS ?

And how can I avoid this loop?

1 Answer 1

1

Try changing your last condition by removing the leading and trailing slashes. You've rewritten your URI to:

/init.php

But there's no trailing slash like there is in the condition that you've provided, so the rule gets applied again. It should look like:

RewriteCond %{REQUEST_URI} !(init\.php|content|images|css|js|fonts|pdfs)

Not sure why you insist on having the trailing slash at the end of your condition here:

#                 with this / here, it will never match init.php --------v
RewriteCond %{REQUEST_URI} !/(init\.php|content|images|css|js|fonts|pdfs)/

But you can solve it by just excluding init.php directly:

RewriteCond %{REQUEST_URI} !init.php

So, just so it's clear, your last set of conditions/rule will look like:

RewriteCond %{REQUEST_URI} !init.php
RewriteCond %{REQUEST_URI} !/(content|images|css|js|fonts|pdfs)/
RewriteRule ^([a-z]{2})/(.*)$ init.php?lang=$1&request=$2&site=basecamp [L,QSA]

Or worst case, just add this in the very beginning of your rules:

RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]

Which prevents any kind of rewrite engine looping altogether.

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks for your patience so far Jon. So here's the updated rule that doesn't work: RewriteCond %{REQUEST_URI} !/(init\.php|content|images|css|js|fonts|pdfs)/ RewriteRule ^([a-z]{2})/(.*)$ /init.php?lang=$1&request=$2&site=basecamp [L,QSA]
I had forgotten to remove the trailing slash. But I copied and pasted the rules exactly as you wrote them out, and I'm still getting the same issue.
If you look at the url in my question, you'll see that it doesn't include init.php, so that's probably why !init.php is not working
@gAMBOOKa !init.php means anywhere in the URI, there cannot be an init.php. The URL in question is init.php?lang=$1&request=$2&site=basecamp and it most definitely contains an init.php
@gAMBOOKa it prevents all looping. The rewrite engine will put a URI through all the rules, and if it comes out different than it went in (e.g. if it was changed at all), the rewrite engine puts the resulting URI back through all the rules, and it'll do this forever either the URI is the same going in and coming out, or a 500 server error.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.