2015-04-06 41 views
0

我有一個關於mod_rewrite的問題 - 我有以下網址:PHP - mod_rewrite的與參數

http://website.com/profile/index.php?a=profile&u=username 

我試圖重寫到:

http://website.com/profile/user/username 

我已經在我的.htaccess以下文件:

RewriteEngine on 
RewriteRule ^/profile/user/([^/]*)$ /profile/index.php&a=profile&u=$1 [L] 

雖然當去重寫的URL,我沒有看到該頁面。我只看到默認的index.php頁面。我試圖通過印刷得到paramters:print_r($_GET);

這給了我如下:

Array ([a] => u [q] => /username) 

現在我的問題是 - 我怎麼能改寫第一URL到第二?顯然,a是空的,而u還含有/

+1

你試試:'^重寫規則/型材/用戶/([^ /] *)$ /index.php&a=$1&u=$2 [L]' – 2015-04-06 08:08:26

+0

然後@Testing了'了'參數變爲' user' - 應該是'profile'以便index.php頁面獲得正確的文件。 – oliverbj 2015-04-06 08:10:03

+0

看我上面的編輯.. @oliverbj – 2015-04-06 08:14:38

回答

1
RewriteEngine on 
RewriteRule ^profile/user/([^/]*)$ index.php?a=profile&u=$1 [L] 

對於網址:localhost/profile/user/test - print_r($_GET)回報:

Array ([a] => profile [u] => test) 
-2

Mode_rewrite

試試這個

RewriteCond %{QUERY_STRING}  ^$    [OR] 
RewriteCond %{QUERY_STRING}  ^query=(.*)$ [NC] 
RewriteRule ^/old-search$  /search/%1  [NC,L,R=301] 

OR

RewriteCond %{QUERY_STRING}  ^view=tags$  [NC] 
RewriteRule ^/blog$    /profile/users/  [NC,L,R=301] 

RewriteCond %{QUERY_STRING}  ^view=posts$ [NC] 
RewriteRule ^/blog$    /profile/   [NC,L,R=301] 


RewriteRule ^/profile$ /profile/%1 [NC,L,R=301] 
+0

你真的這會滿足OP的要求嗎? – 2015-04-06 08:13:58

+0

@Aelmasry什麼是「舊搜索」和「博客」? – oliverbj 2015-04-06 08:19:22