我嘗試使用下面的代碼重寫動態URL動態網址:問題重寫使用mod_rewrite
RewriteRule (.*)/$ index.php?location=$1
RewriteRule (.*)/(.*)/$ index.php?location=$1&company=$2
我真的很需要兩個重寫,你可以從上面的代碼中看到。首先,如果全部存在,我需要頁面重寫位置。例如,它會將site.ccom/index.php?location = sandiego變成site.com/sandiego/
這是正常工作。
但是,當我嘗試添加第二個變量時失敗。它設法檢測& company = 1變量,但由於某種原因它將?location = sandiego變量作爲'index.php'返回。例如,如果我輸入以下內容:site.com/san-diego/1/,然後嘗試獲取$ location和$ company變量,它將只會成功獲取$ company變量,並且$ location變量將被設置到'index.php',而不是'san-diego'。
任何幫助將不勝感激。
對不起,沒有那些工作在所有。他們都返回了404錯誤。 – Jeremy 2011-03-23 21:57:51
對不起,我已將'index.php'重命名爲'rewrite.php'進行測試,並忘記將其改回... =>編輯我的答案。 – 2011-03-23 22:08:06
是的,一個想法,並重新命名爲index.php。但它仍然不起作用。回到我原來的代碼,我可以得到任何一個或另一個工作。如果我只是使用這一行:'RewriteRule(。*)/ $ index.php?location = $ 1',它會完全重定向site.com/sandiego/。如果我只使用這一行:'RewriteRule(。*)/(。*)/ $ index.php?location = $ 1&company = $ 2',它將完全重定向到site.com/sandiego/1/。但是,當我一起使用它們時,它們全部崩潰。 – Jeremy 2011-03-23 22:09:58