1

i've got some lil problem with my htaccess. My Links: http://example.com/log/?lang=en where log - it's a different directory and lang (en or uk or ru) But I want some pretty url LIKE: http://example.com/en/log/

Before I user regex:

RewriteRule ^([a-z]{2})/?$ index.php?lang=$1 [L,NC,QSA] 

RewriteRule ^([a-z]{2}(-[A-Z]{2})?)/(.*) $3?lang=$1 [L,NC,QSA] 

But can't find some decision for pretty URL

What I want:

By my logic I have to cut lang=en and paste together my host with request_uri like: host/en/?request_uri But how to do it?

Logan
  • 13
  • 6

1 Answers1

1

Have it this way:

RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} \s/+(log)/\?lang=([^\s&]+) [NC]
RewriteRule ^ /%2/%1? [R=302,L]

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^ - [L]

RewriteRule ^([a-z]{2})/?$ index.php?lang=$1 [L,NC,QSA] 

RewriteRule ^([a-z]{2}(-[A-Z]{2})?)/(.*) $3?lang=$1 [L,NC,QSA] 
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • Which URL is causing redirection loop? DO place your full & latest .htaccess in question. – anubhava Jan 23 '14 at 17:26
  • Oh I'm sorry its all working now, thanks a lot. Last question if dirname isn't log? – Logan Jan 23 '14 at 17:42
  • number of folders ~ 100 – Logan Jan 23 '14 at 17:43
  • Change your first rule to: `RewriteCond %{THE_REQUEST} \s/+([^/]+)/\?lang=([^\s&]+) [NC]` to match any dirname there. – anubhava Jan 23 '14 at 17:48
  • http://example.com/uk/registration/?lang=en How replace old value "uk" by new value "en"? – Logan Jan 23 '14 at 17:53
  • Try this: `RewriteCond %{THE_REQUEST} \s/+[^/]+/(.*?)\?lang=([^\s&]+) [NC]` and in next line: `RewriteRule ^ /%2/%1? [R=302,L]` – anubhava Jan 23 '14 at 17:58
  • with this isn't correct work RewriteCond %{THE_REQUEST} \s/+[^/]+/(.*?)\?lang=([^\s&]+) [NC] and in next line: RewriteRule ^ /%2/%1? [R=302,L] all pages redirect on sitename.com/en/ but right path is sitename.com/en/dir/ or sitename.com/en/dir99/ sitename.com/?lang=en not working 2oo. Sorry can u help me again)) – Logan Jan 23 '14 at 18:30
  • Actually it is getting difficult to understand all the requirements with these comments. But try changing it to: `RewriteCond %{THE_REQUEST} \s/+[^/]+/(.+?)\?lang=([^\s&]+) [NC]` – anubhava Jan 23 '14 at 18:34
  • If it doesn't work or you want more help then I request you to create a new question listing all the scenarios and I will attend it. – anubhava Jan 23 '14 at 18:35
  • 1
    Thank you, when I'm ready will create a new question. Thank you very much for your help.:))))))) – Logan Jan 23 '14 at 18:52