1

I want to write a RewriteRule that both cleans the URL and puts the language detection before the file.

I have looked at questions like .htaccess for language detection, redirecting + clean urls and .htaccess rule for language detection.

With these two combined I made a solution that sometimes works and sometimes doesn't.

My structure: domain.com/subfolder/news.php?lang=en

What I want is: domain.com/subfolder/en/news

My code so far:

RewriteBase /subfolder/
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    # Language Detection
    RewriteRule ^(en|sv)/(.*)$  $2?lang=$1 [QSA,L]
    ## Remove .php extensions
    RewriteRule ^([^\.]+)$ $1.php [NC,L]`

This did work on some paths, but not on all (they had the same structure).

How should I solve this?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
Noyce
  • 43
  • 4

1 Answers1

1

Try with:

RewriteBase /subfolder/

# Language Detection
RewriteRule ^(en|sv)/(.*)$  $2?lang=$1 [NC,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
## Remove .php extensions
RewriteRule ^([^\.]+)$ $1.php [NC,L]
Croises
  • 18,570
  • 4
  • 30
  • 47
  • `RewriteRule ^(en|sv)/(.*)$ $2?lang=$1 [L,NC,QSA]` Added the "L" and that order did work, thanks! – Noyce Jun 28 '16 at 06:35