2015-09-22 73 views
2

我在.htaccess文件做了URL重寫爲manage_districts.php如下條件:或htaccess的URL重寫

RewriteRule ^manageDistricts/([0-9]+)/?$ manage_districts.php?editid=$1 [NC,L] 
RewriteRule ^manageDistricts/([0-9]+)/?$ manage_districts.php?delid=$1 [NC,L] 

在這裏你可以看到,對於這兩種,編輯和刪除操作我有一個相同的頁面,所以,而不是寫相同的規則爲同一個文件我想寫一個單一的規則,我可以通過editid以及delid或條件

我已經嘗試此語法,

RewriteRule ^manageDistricts/([0-9]+)/?$ manage_districts.php?(editid|delid)=$1 [NC,L] 

,但它不工作。

+0

我不明白。你想要editid和delid來獲取參數?那爲什麼不用manage_districts.php?editid = $ 1&delid = $ 1 [NC,L] ??? – Amarnasan

+0

@ Amarnasan我沒有嘗試過。等等...會讓你知道。謝謝 ! – vitally

+0

nope。它是刪除我的記錄,當我點擊編輯按鈕 – vitally

回答

1

您不能對兩個不同的操作使用相同的URL。因此,使用「編輯」或「刪除」值添加第二個參數。

RewriteRule ^manageDistricts/edit/([0-9]+)/?$ manage_districts.php?editid=$1 [NC,L] 
RewriteRule ^manageDistricts/delete/([0-9]+)/?$ manage_districts.php?delid=$1 [NC,L] 

而在你的HTML:

<a href="<?php echo COLLEGE_INFO_ADMIN_BASE_PATH ?>manageDistricts/edit/<?php echo $row['id']?>" title="Edit">Edit</a> 

<a href="<?php echo COLLEGE_INFO_ADMIN_BASE_PATH ?>manageDistricts/delete/<?php echo $row['id']?>" onClick="return confirm('Are you sure,You want to delete this Record?');" title="Delete">Delete</a> 
+0

是的,我已經做了 – vitally

+0

RewriteRule^manageDistricts /([0-9] +)/?$ manage_districts.php?editid = $ 1 [NC,L] RewriteRule^manageDistricts /([0-9] +)/? $ manage_districts.php?delid = $ 1 [NC,L] – vitally

+0

這不是我寫的。 – Amarnasan