0

It is duplicate i know but i am stuck in here , i also tried this link URL rewriting with PHP but i need to ask someone, i am new and [actually couldn't get it] and i couldn't search more because of somethings. the problem is i get 404 ERROR ... so anyone help ?

# BEGIN

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /Folder/
    RewriteRule ^index\.php$ - [L]

    RewriteCond %{HTTP:Accept-Language} ^en [NC]
    RewriteRule ^$ Folder/en/ [L,R=301]

    RewriteCond %{HTTP:Accept-Language} ^de [NC]
    RewriteRule ^$ Folder/de/ [L,R=301]

    RewriteCond %{HTTP:Accept-Language} ^fa [NC]
    RewriteRule ^$ Folder/nl/ [L,R=301]

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-l

    RewriteRule ^(en|de|fa)/?$ index.php?lang=$1 [QSA,NC,L]
</IfModule>

# END

1 Answers1

0

Suggested Solution

A better approach could be a single script at the root folder that handles all requests. This is an idea that can be better described with examples:

  1. www.domain.com/ always showing in the browser's address bar but going internally to www.domain.com/lang_handler.php?lang=sv or
  2. www.domain.com/page1/ always showing in the browser's address bar but going internally to www.domain.com/lang_handler.php?lang=sv&target_page1=page1

This can be achieved in .htaccess with mod_rewrite directives. Here is an example:

RewriteEngine On
RewriteBase  /

# Set managed languages here, except default (en)
RewriteCond %{HTTP:Accept-Language} ^(sv|ne|no).*$ [NC]

# Replace the names of the script and the parameters in the next 2 lines
RewriteCond %{REQUEST_URI} !lang_handler\.php              [NC]
RewriteRule ^([^/]+)?/?$  lang_handler.php?lang=%1&target_page1=$1  [L,QSA]

# If no match, set English
# Replace the names of the script and the parameters in the next 2 lines
RewriteCond %{REQUEST_URI}  !lang_handler\.php             [NC]
RewriteRule ^([^/]+)?/?$  lang_handler.php?lang=en&target_page1=$1  [L,QSA]
Luiz Brz Developer
  • 428
  • 1
  • 4
  • 14