2014-01-06 33 views
0

有些時候,現在我在我的htaccess並沒有辦法得到我想要的......郎參數改寫

我想改寫爲如下:

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 

.. 。

任何想法該怎麼做?

-------- -------編輯

我的htaccess實際上是這樣的:

<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> 

結果:

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 

我已成功地通過放置在中繼線父目錄中的htaccess將幹線/公用文件夾中的默認域目標設置爲

+0

我試用了一下幾件事情,但我真的沒有htaccess的條件 – VeZoul

回答

0

將這2個在/trunc/public/.htaccess文件規則:

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] 
+0

任何知識,我得試試我的生產服務器上...我才意識到,我需要的條件對於我的開發服務器,其基本網址就像http://www.mydomain.net/trunk/public 然後我試着 '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]'沒有成功 – VeZoul

+0

1.您不能在' RewriteRule'和2.什麼是/ trunc/public我不明白 – anubhava

+0

/trunk/public是站點所在的文件夾 – VeZoul