0

I made a website for arabic and english. All the files are stored in the root directory. I didn't made any separate folder for arabic or english nor any file for arabic or english. I just made a two language array for arabic or english. If url says arabic then data from arrayarabic will fetch and same case of english.

What I am requesting to convert My current url is

http://www.example.com/viewjob.php?job_id=11031

I want to convert if to http://www.example.com/ar/viewjob.php?job_id=11031 but there is no separate folder for ar.

Please let me know... thanks.

1 Answers1

3

You can accomplish this quite easily with mod_rewrite. When an url starts with either "ar" or "en", you want to take the rest of the url, and internally rewrite to the rest of the url and append a parameter to the rest of the query string:

RewriteEngine on

RewriteRule ^(en|ar)/(.*)$ $2?lang=$1 [QSA,L]

See the documentation.

Sumurai8
  • 18,213
  • 9
  • 58
  • 88
  • Brother, do i to change all the url to include ar or en ?? like http://www.example.com/viewjob.php?job_id=11031 to http://www.example.com/ar/viewjob.php?job_id=11031. Now my url doesn't inlucde ar or en. – user3477550 Apr 25 '15 at 09:56
  • This work excatly the required. Thank you very very much... love your answer. – user3477550 Apr 25 '15 at 10:19
  • The urls on your site need to be changed so they include the language. If they are relative it will automatically go well, but you'll need to make css/js/image urls absolute. – Sumurai8 Apr 25 '15 at 10:35
  • Dear, its working in local server but not on the live server. Please could you help me again. the domain is http://afaqemployment.com/employers.php is working fine but http://afaqemployment.com/ar/employers.php – user3477550 Apr 25 '15 at 12:07
  • Enable mod_rewrite ([see this question](http://stackoverflow.com/questions/869092/how-to-enable-mod-rewrite-for-apache-2-2)) and make sure that `AllowOverride` is at least `FileInfo` in the main config file. – Sumurai8 Apr 25 '15 at 12:12
  • Brother, please hold on, i'll check and let you know. I have the below code in my file # Lines That should already be in your .htacess Order Allow,Deny Deny from All Options +FollowSymLinks -MultiViews # Turn mod_rewrite on RewriteEngine On RewriteBase / RewriteRule ^(en|ar)/(.*)$ $2?lang=$1 [QSA,L] – user3477550 Apr 25 '15 at 12:20
  • The main config file is httpd.conf, not a .htaccess file. – Sumurai8 Apr 25 '15 at 12:28
  • But i cannot find this file in my server may be its hidden. How can i access this ? can i make a new file and add to my root ? – user3477550 Apr 25 '15 at 12:39
  • http://stackoverflow.com/questions/12202021/where-is-my-httpd-conf-file-located-apache – Sumurai8 Apr 25 '15 at 12:45
  • Ok bro, thanks.. i fed up.. i cannot find. I'll use session to change the language. thanks. – user3477550 Apr 25 '15 at 12:53