2014-02-18 16 views
1

下面的URL是我需要的.htaccess重寫的呢?鑑於=家/視圖/家

http://example.com/?view=home 

而如果我的網址是非常動態$ _GET參數有多個$ _GET?

http://example.com/?view=home&url=this&name=test&id=that 

我試了幾次重寫模塊,但不能得到我想要的結果。 下面是我重寫引擎:

Options +FollowSymlinks 
RewriteEngine On 

# specific rule 
RewriteCond %{QUERY_STRING} ^([^=]+)=([^&]+) 
RewriteRule ^(constant)$ /index.php?view$1 [L] 

# general catch-all 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php?url=$1 [L] 

我目前的虛擬主機是在Linux上虛擬主機,在本地運行測試我的文件上XAMPP環境。

回答

0

可以將此代碼重定向從?view=home/view/home

Options +FollowSymlinks 
RewriteEngine On 

RewriteCond %{THE_REQUEST} /\?([^=]+)=([^\s&]+) [NC] 
RewriteRule^/%1/%2? [R=302,L] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([^/]+)/([^/]+)/?$ /index.php?$1=$2 [L,QSA] 

# specific rule 
RewriteCond %{QUERY_STRING} ^([^=]+)=([^&]+) 
RewriteRule ^(constant)$ /index.php?view$1 [L] 

# general catch-all 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php?url=$1 [L] 
+0

嗨感謝您的回答,但是當使用烏爾的.htaccess代碼我目前歌廳內部服務器錯誤。 做上述htaccess的工作對 example.net?view=testing 或example.net/test/view=testing 或example.net/test/index.php?view=testing 我試圖在這個網站HTTP:/ /seo-website-designer.com/HtAccess-301-Redirect-Generator,但沒有線索。 – Mavichow

+0

這適用於'http:// localhost /?view = testing'(請參閱更新後的代碼)我重新測試並且它不會導致500 – anubhava

+0

感謝它的工作!看起來像我的服務器的設置原因當我把'選項+ FollowSymlinks'在htaccess我會得到500內部服務器錯誤,但我刪除它,一切工作順利和魅力!謝謝@anubhava – Mavichow