0

Some times now I'm around my htaccess and no way to get what I want...

I'd like to rewrite as followings :

http://www.mydomain.com/trunk/public/lang/ => http://www.mydomain.com/trunk/public/?l=lang
http://www.mydomain.com/trunk/public/lang/profile => http://www.mydomain.com/trunk/public/profile?l=lang
http://www.mydomain.com/trunk/public/lang/user/45 => http://www.mydomain.com/trunk/public/user/45?l=lang

...

Any idea how to do that?

--------EDIT-------

My htaccess actually looks like :

    <IfModule mod_rewrite.c>
RewriteEngine On
#Transform lang into get parameter
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(fr|en)/$ ?l=$1 [L,QSA]
#Transform lang into get parameter
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(fr|en)/(.+)$ $1?l=$2 [L,QSA]
#This last condition enables access to the images and css folders, and the robots.txt file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|public|images|assets|robots\.txt|css)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

Results :

http://www.mydomain.com/trunk/public/lang/ gives a bonfire 404 error (it tries to load "lang" module)
http://www.mydomain.com/trunk/public/lang/profile gives a server 404 error
http://www.mydomain.com/trunk/public/profile works
http://www.mydomain.com/trunk/public/profile?l=fr works

I have managed to set the default domain destination in the trunk/public folder via an htaccess placed in a the trunk parent directory

VeZoul
  • 500
  • 6
  • 19

1 Answers1

0

Insert these 2 rules in your /trunc/public/.htaccess file:

RewriteEngine On
RewriteBase /trunc/public/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ ?l=$1 [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/(.+)$ $1?l=$2 [L,QSA]
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • I'll have to try on my production server... I just realized that I need conditions for my development server, on which base url is like http://www.mydomain.net/trunk/public I then tried `RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^/trunk/public/([^/]+)?$ /trunk/public/?l=$1 [L,QSA] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^/trunk/public/([^/]+)/(.+)$ /trunk/public/$1?l=$2 [L,QSA]` with no success – VeZoul Jan 06 '14 at 15:57
  • 1. You cannot have leading slash in `RewriteRule` and 2. What is `/trunc/public` I didn't understand – anubhava Jan 06 '14 at 16:15
  • /trunk/public are the folders where the site is in – VeZoul Jan 06 '14 at 18:53
  • Is that the `DocumentRoot` as per your Apache server config? – anubhava Jan 06 '14 at 18:55
  • check edited code. Remember it does in your `/trunc/public/.htaccess` file. – anubhava Jan 06 '14 at 19:08
  • I did add your line but nothing works... I edited the question with all the htaccess file and the results of tests – VeZoul Jan 07 '14 at 09:51
  • Did you place this in `/trunc/public/.htaccess file`? – anubhava Jan 07 '14 at 10:00
  • Yes this is the trunk/public/.htaccess file – VeZoul Jan 07 '14 at 10:01
  • Ok I am on mobile, let me go through edited post once I reach back to my computer. – anubhava Jan 07 '14 at 10:02
  • I edited the question with new information about the htaccess. – VeZoul Jan 09 '14 at 10:10
  • I looked at that but your .htaccess rules aren't the ones I suggested. Let me know what problems you face after using suggested rules. – anubhava Jan 09 '14 at 19:05