2010-10-24 149 views
1

我想從/main.php?page=pages & id = gettingpaidfortakingsurveys到/ main/pages/getting-paid-taking-taking-surveys重定向此網址。CakePHP和.htaccess:如何重定向URL與查詢字符串

謝謝!

[UDPATE]

我測試了它在我現有的CakePHP的.htaccess並沒有奏效。

<IfModule mod_rewrite.c> 
RewriteEngine on 
RewriteRule ^/main.php?page=(.+)&id=(.+) /main/$1/$2 [NC] 
RewriteRule ^$ app/webroot/ [L] 
RewriteRule (.*) app/webroot/$1 [L] 
</IfModule> 
+0

順便說一下,不要忘記將IfMaodule更改爲IfModule。 – 2010-10-25 14:27:47

回答

0

既然你似乎要與Apache的.htaccess要做到這一點,你需要的mod_rewrite模塊。在.htaccess中,你需要這樣的東西:

RewriteEngine on 
RewriteRule ^main.php?page=(.+)&id=(.+) /main/$1/$2 [NC] 

這應該讓你/ main/pages/gettingpaidfortakingsurveys。這不會連字符,我不確定你會做到這一點,沒有太複雜的東西。

+0

嗨那裏似乎代碼沒有工作。我更新了這篇文章,所以你可以看到新的.htaccess。它實際上是在cakephp – 2010-10-24 09:19:02

+0

你的.htaccess比你在問題中提出的問題要多得多,所以我不能幫你解決問題,但是你有一個錯誤的'IfMaodule'。如果你不正確地做其他事情,請查閱'mod_rewrite'的文檔,它只是基本的正則表達式。 http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html – greg 2010-10-24 12:16:51

+0

我弄錯了這個錯字。我需要它修復,所以我在webroot文件夾中創建了一個main.php並做了一些重定向,這是暫時的。謝謝你的時間。 – 2010-10-24 13:16:41

0

你有沒有試過這個,我假設這只是一個頁面的重定向。你需要把它放在Cake重寫塊的上面。第二部分必須是完整的URL:

Redirect 301 /main.php?page=pages&id=gettingpaidfortakingsurveys http://www.domain.com/main/pages/getting-paid-for-taking-surveys 
<IfModule mod_rewrite.c> 
    RewriteEngine on 
    RewriteRule ^$ app/webroot/ [L] 
    RewriteRule (.*) app/webroot/$1 [L] 
</IfModule> 

如果重寫是暫時的,替代302 301

的URL /主體部分看起來並不很蛋糕友好。不應該只是/ pages/...?

相關問題