2016-07-06 29 views
0

我有真正的很多關於CakePHP的,和PHP rewrite_mod,但讀音字這麼多關於如何使用它,因爲我沒有關於正則表達式的知識迷惑。 我怎麼能有這樣的事情?PHP假網址,複雜的.htaccess rewrite_mod

mywebsite.com/ /=> mywebsite.com/ ?郎= EN

mywebsite.com/ /約=> mywebsite.com/about/ ?郎= EN

mywebsite.com/ EN /搜索/?查詢= +你好世界=> mywebsite.com/search/ ?查詢= +你好世界& LANG = EN

所以在現實中我的文件是這樣的:

public_html/about/index.php 
public_html/search/index.php 
public_html/index.php 

但即時作假就像

public_html/en/about/index.php 
public_html/en/search/index.php 
public_html/en/index.php 

,需要保護的URL,並通過GET傳遞的參數,我不明白怎麼在.htaccess中設置一個如此複雜的url控制器

我也嘗試了下面這個,但沒有出去,有沒有任何示例項目? cakephp 3 parameter url

回答

0

本質上,您重新排列了請求URL。這意味着,您必須分別捕獲(...)零件,並將它們放在替代品$...中。您還希望保留現有的查詢字符串,該字符串需要使用QSA|qsappend標誌。 RewriteCond是爲了防止重寫循環。如果規則應用一次,則不應再次使用該規則。

RewriteCond %{QUERY_STRING} !lang= 
RewriteRule ^(..)(.*)$ $2?lang=$1 [L,QSA] 

要了解有關正則表達式的更多信息,請參閱Apache - Regular Expressions

+0

我不知道爲什麼QSA的服務器printss錯誤500,並且它繼續重定向到** HIDDEN **目標'RewriteEngine on RewriteRule^lang - (。* +)/?$ index.php?lang = $ 1 [L]',這條線我得到了一點點附近,但即時通訊仍然遠離頁面的網址。對於類似'/ lang-EN/aboutus /?article = 0'這樣的鏈接,var_dumps'array(1){[「lang」] => string(11)「EN/aboutus /」}';而如果不是?我使用&var_dumps'array(2){[「lang」] => string(11)「EN/aboutus /」[「article」] => string(1)「0」}'現在我必須能夠從$ _GET ['lang']提取aboutus並將其放在index.php – development

+0

的地方對不起,這是我的錯,我錯過了檢查重寫循環。請參閱最新的答案。 –