簡體   English   中英

CakePHP和.htaccess:如何使用查詢字符串重定向URL

[英]CakePHP and .htaccess: how to redirect url with query string

我想將此網址從/main.php?page=pages&id=gettingpaidfortaking調查重定向到/ main / pages / getting-paid-for-takeing調查。

謝謝!

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

由於您似乎想使用Apache的.htaccess進行此操作,因此需要mod_rewrite模塊。 在.htaccess中,您將需要以下內容:

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

這應該使您/ main / pages / gettingpaidfortaking調查。 這不會連詞,我不確定您是否可以做到這一點而不會太復雜。

您是否嘗試過,我假設這只是一個頁面的重定向。 您需要將其放在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。

網址的/ main部分看起來不太適合Cake。 不應該是/ pages / ...嗎?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM