0

The goal is to add the locale "en" at the beginning of the URLs which doesn't have it.

Example

https://example.com/document/file.php

Becomes

https://example.com/en/document/file.php

The following rule works fine alone:

RewriteCond %{REQUEST_URI} !^/[a-z]{2}/
RewriteRule ^(.*) /en/$1 [R=302,L]

The thing is that I'm stucked in rewriting the URL after the Symfony rules.

  • Determine the RewriteBase automatically and set it as environment variable. RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$ RewriteRule ^(.*) - [E=BASE:%1]

  • Sets the HTTP_AUTHORIZATION header removed by Apache RewriteCond %{HTTP:Authorization} . RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

  • Remove app.php from the URL RewriteCond %{ENV:REDIRECT_STATUS} ^$ RewriteRule ^app_pre_prod\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]

  • Add the requested page to the index (exemple index.php/login) RewriteCond %{REQUEST_FILENAME} -f RewriteRule ^ - [L] RewriteRule ^ %{ENV:BASE}/app.php [L]

The best result I have is: nothing changes.

Or by deactivating the third rule and removing the flag [L] of the last one, the following result:

https://example.com/en/app.php/document/file.php
MrWhite
  • 12,647
  • 4
  • 29
  • 41
  • "after the Symfony rules" - why _after_ the Symfony rules? That doesn't appear to make sense (and would indeed be a problem). This would seem to be an external redirect and should go at the top of the file. Or, don't redirect at all and default to `en` in your application? – MrWhite Feb 13 '19 at 18:04
  • Or are these URLs that you need to inject `/en` nothing to do with Symfony, ie. entirely outside of the framework? (Although you still wouldn't do this _after_ the Symfony rules.) – MrWhite Feb 13 '19 at 18:13
  • You're right, adding `/en` has nothing to do with Symfony. I was assuming that it should goes after the Symfony rewrite rules but I was probably wrong according to your comment. In the other hand, placing the locale rewrite before gives the last result of the post. – DeepBlueMussel Feb 14 '19 at 08:42
  • By default `/en` is added in the application. The thing is that this locale is new and all the links that have been shared before doesn't have it. In a matter of SEO and ressource availabilty we must rewrite these old URLs. – DeepBlueMussel Feb 14 '19 at 08:58

0 Answers0