2011-04-24 57 views
0

比方說,我有以下形式的網址:myurl.com/index.php?m=1,我想它映射到myurl.com/aboutus,這意味着,我希望瀏覽器在上面的欄中顯示後一個網址。 所以我首先要做的就是抓關於我們並將它映射到index.php?m = 1mod_rewrite的要求非常網址

RewriteRule ^aboutus$ /index.php?m=1 

現在如果我型myurl.com/aboutus,正確的頁面顯示,但我想有它相反的方式一樣,所以即使當我鍵入/index.php?m=1,我想瀏覽器顯示/ aboutus。

我怎樣才能實現與mod_rewrite?

任何幫助表示讚賞!

歡呼聲,
b

回答

2
RewriteEngine on 


RewriteCond %{QUERY_STRING} =m=1 
RewriteCond %{REQUEST_URI} =/index.php 
RewriteRule ^.* /aboutus? [R=301] 


RewriteRule ^aboutus /index.php?m=1 [QSA] 

更新#1

RewriteEngine on 

RewriteCond %{QUERY_STRING} =m=1 
RewriteCond %{REQUEST_URI} =/index.php 
RewriteRule ^.* /kepek? [R=301] 

RewriteCond %{QUERY_STRING} =m=2 
RewriteCond %{REQUEST_URI} =/index.php 
RewriteRule ^.* /paroknak? [R=301] 

RewriteCond %{QUERY_STRING} =m=3 
RewriteCond %{REQUEST_URI} =/index.php 
RewriteRule ^.* /magam? [R=301] 

RewriteCond %{QUERY_STRING} =m=4 
RewriteCond %{REQUEST_URI} =/index.php 
RewriteRule ^.* /kapcsolat? [R=301] 


RewriteRule ^kepek /index.php?m=1&redirected=1 [QSA] 
RewriteRule ^paroknak /index.php?m=2&redirected=1 [QSA] 
RewriteRule ^magam /index.php?m=3&redirected=1 [QSA] 
RewriteRule ^kapcsolat /index.php?m=4&redirected=1 [QSA] 
+0

的'RewriteCond',但我怎麼能爲其他數字呢?對不起,我的問題根本沒有概括:( – 2011-04-24 20:02:16

+0

)如果有很多這些數字,我會建議從/index.php?m = ...重定向到index.php本身的正確命名頁面。檢查QUERY_STRING。 – akond 2011-04-24 20:06:51

+0

只有4個,我不能修改index.php: -/ – 2011-04-24 20:09:59

-2
RewriteRule ^aboutus$ /index.php?m=1 [L] 
RewriteRule ^index.php\?m=1$ /aboutus [301,L] 
+0

這給我500 - 內部服務器錯誤出於某種原因。 – 2011-04-24 19:49:35

+0

這個規則實際上是倒退的。它給你500錯誤的原因是文件'aboutus'不存在。 – Compeek 2011-04-25 02:23:07

+1

這是錯誤的幾個原因。 500錯誤實際上是因爲第二條規則上的標誌不正確,它應該是'[R = 301,L]'。另外,由於用戶表示規則在'.htaccess'文件中,因此RewriteRules將不會與前導'/'匹配。另外,'RewriteRule'的第一組無法與查詢字符串匹配,因此需要使用'%{QUERY_STRING}' – clmarquart 2011-04-25 14:50:58

0

您是否希望號映射到約,2->新聞像1頁>。 ..?

此外,您期望的行爲聽起來像一個無限的重定向循環。

+0

是的,這正是我想要的。對我來說它看起來也像一個無限循環,但我不想在url中顯示任何參數,但我已經有了頁面,並且在html中鏈接使用params編碼,就像常規獲取url一樣,所以我無法修改他們相當相當:( – 2011-04-24 19:58:14