0

Why is this causing a redirect loop?

Options +FollowSymlinks
RewriteEngine on
RewriteBase /summary/1/document/

RewriteRule !^[a-z]{2}/ /summary/1/document/en/ [L,R]
RewriteRule ^([a-z]{2})/ ../index.php?lang=$1&type=document

What I am trying to achieve is:

If there's no language specified, redirect to english:

Example:

website.com/summary/1/document --> website.com/summary/1/document/en/
website.com/summary/1/document/fr/ [no redirect]

And when a language is specified, rewrite internally to ../index.php with lang and type parameters.

1 Answer 1

1

From Flag L: Apache Docs: flag_l :

If you are using RewriteRule in either .htaccess files or in <Directory> sections, it is important to have some understanding of how the rules are processed. The simplified form of this is that once the rules have been processed, the rewritten request is handed back to the URL parsing engine to do what it may with it. It is possible that as the rewritten request is handled, the .htaccess file or section may be encountered again, and thus the ruleset may be run again from the start. Most commonly this will happen if one of the rules causes a redirect - either internal or external - causing the request process to start over.


Since, rewritten request is handed back to the URL parsing engine, after redirect from the first rewrite rule,

Try this:

Options +FollowSymlinks
RewriteEngine on
RewriteBase /summary/1/document/

RewriteRule ![a-z]{2}/$ /summary/1/document/en/ [NC,L,R]
RewriteRule ^([a-z]{2})/$ ../index.php?lang=$1&type=document [L,QSA]
Sign up to request clarification or add additional context in comments.

Comments

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.