2011-06-14 63 views
0

我在嘗試將mod_rewrite集成到我現有的頁面中完全失敗。目前,我從頭開始建立一個新的網站,在那裏我有一些乾淨的網址,如:如何使用參數重定向url?

http://www.example.nl/nl/example 

舊網站,運行CMS變得簡單,具有一定的不改寫的URL,將需要重定向到新的頁面。這些網址是這樣的:像的

http://www.example.nl/index.php?page=cake-and-pie&hl=nl_NL 

但較短的版本:

http://www.example.nl/index.php?page=cake-and-pie 

也行。

我花了一段時間才弄清楚帶參數的網址不能簡單地用「重定向301」重定向,就像我正常做的那樣。所以我嘗試了一些在線的mod_rewrite生成器,如thisthis,但這些規則輸出的規則只會導致404錯誤(重定向根本不起作用)。

我的.htaccess文件目前看起來是這樣的:

RewriteEngine On 
RewriteBase/

# remove .php; 
RewriteCond %{THE_REQUEST} ^GET\ (.*)\.php\ HTTP 
RewriteRule (.*)\.php$ $1 [R=301] 

# remove index 
RewriteRule (.*)/index$ $1/ [R=301] 

# remove slash if not directory 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_URI} /$ 
RewriteRule (.*)/ $1 [R=301] 

# add .php to access file, but don't redirect 
RewriteCond %{REQUEST_FILENAME}.php -f 
RewriteCond %{REQUEST_URI} !/$ 
RewriteRule (.*) $1\.php [L] 

舊的頁面會抓住存在。 我如何將舊頁面重定向到新頁面?

謝謝。

編輯

RewriteCond %{QUERY_STRING} =page=pie 
RewriteRule ^index\.php$ /nl/? [L,R=301] 
RewriteCond %{QUERY_STRING} =page=pie&hl=nl_NL 
RewriteRule ^index\.php$ /nl/? [L,R=301] 

似乎這樣的伎倆。這當然是每個網址的手冊,但我只有幾個。

回答

0
RewriteEngine On 
RewriteBase/
RewriteRule ^(.+)/([^/]+)/?$ index.php?page=$1&hl=$2 
RewriteRule ^([^/]+)/?$   index.php?page=$1 [QSA] 
+0

不知何故,這似乎打破...該網頁沒有重定向。 – Lg102 2011-06-14 15:26:50