2013-03-19 131 views
0

可以將用戶從url http://localhost/welcome?url=1&another=2重定向到index.php?another = 2 & url = welcome?我的意思是,我想將所有查詢字符串放在解析的部分之前。可能嗎?Apache,重定向url之前放置查詢字符串?

我知道我可以做這樣的事情:用$_SERVER[ 'REDIRECT_QUERY_STRING' ] RewriteRule ^(.*)$ index.php?%{QUERY_STRING}&url=$1 [QSD,L] ,趕上URL在PHP,但我想獲得從GET數組查詢字符串。

如果我只是讓我有網址等於index.php(文件名),如果我改變的標誌QSA,查詢字符串所有重定向後添加...

任何想法?

- 編輯 -
我查了一些問題,我發現,這是因爲循環的完成。 我已經這樣做了,但也許有人有更好的想法如何解決這個問題。

RewriteCond %{QUERY_STRING} !&rw=1$ [NC] 
RewriteRule ^(.*)$   index.php?%{QUERY_STRING}&url=$1&rw=1 [QSD,L] 

回答

1

能夠重定向從URL http://localhost/welcome?url=1&another=2用戶到index.php?另一= 2 & URL =歡迎?

是的,你可以在.htaccess文件的根目錄試試這個:

Options +FollowSymlinks -MultiViews 
RewriteEngine On 
RewriteBase/
RewriteCond %{REQUEST_URI} !index\.php    [NC] 
RewriteCond %{QUERY_STRING} ^url=1&([^=]+)=([\d]+)/? [NC] 
RewriteRule ^(.*)  /index.php?%1=%2&url=$1?   [NC,L] 

地圖默默:

http://localhost/par1?url=1&par2=val2

要:

http://localhost/index.php?par2=val2&url=par1

其中par1,par2和數字val2是動態字符串。

對於永久重定向,與[R = 301,NC,L]

+0

謝謝,效果很好替換[NC,L] :) – 2013-03-19 16:05:31