2016-09-29 31 views
1

想我再也網址如何重寫一個URL的一部分

http://www.example.com/se/products/details/23 
http://www.example.com/se/company/about 
http://www.example.com/se/customers/europe/john-doe 
etc. 

我希望他們rewrite

http://www.example.com/en/products/details/23 
http://www.example.com/en/company/about 
http://www.example.com/en/customers/europe/john-doe 
etc 

這意味着不管用什麼語言自帶他們rewrited到en,他們看到他們各自的語言在地址欄中,但頁面正在從服務器'en'

我的規則是這樣的

# Pass through the original path as a query parameter, and retain the existing parameters. 
    RewriteCond %{REQUEST_URI} ^(.*)$ 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteRule .* framework/main.php?url=%1 [QSA] 

    RewriteRule ^se/(.+?)\/?$ /en/$1 [L] 

該項目基於SilverStripe框架。

而且這也沒有工作,顯示404頁未找到錯誤

我們怎樣才能做到這一點?

+0

「這沒有工作」。怎麼了?你能告訴我們重寫日誌嗎? – undone

+0

@undone,它顯示404頁未找到錯誤 – WatsMyName

+0

如何重寫日誌?你可以把日誌放在這裏嗎? – undone

回答

1

重新排序規則和有它這樣的:

RewriteEngine On 

RewriteRule ^se(/.*)?$ en$1 [L,NC] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule^framework/main.php?url=%{REQUEST_URI} [L,QSA] 
+1

這個工程,謝謝你的夥計:) – WatsMyName

0

嘗試像這樣,

Options -MultiViews 
RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^se/(.+?)\/?$ /en/$1 [L] 

RewriteRule ^se/(.*) en/$1 [L] 
+0

這沒有奏效,第一個給500錯誤,第二個導致你404錯誤。 – WatsMyName

+0

兩件事,我假設你在根中應用這些規則,其次你必須處理重寫的en /文本/文本與其他一些內部重寫原始URL前'page.php?lang?= en&detail = 23'檢查或提供原始網址。 –

+0

其實這個項目是基於'SilverStripe'框架的,所以沒有原始的URL,因爲你已經指定了。 Silverstripe有自己的路由路徑。 – WatsMyName