2012-01-31 59 views
0
重寫URL

我的錨是這樣重定向和用mod_rewrite

<a href="http://localhost/haveg/employer?id=7003&title=the-message-title">employer</a> 

,當我點擊錨我想在這裏達到

http://localhost/haveg/employer/7003/the-message-title 

到目前爲止,我已經寫了這個.htacess代碼

Options +FollowSymLinks 
Options +Indexes 
RewriteEngine on 
RewriteBase/
RewriteRule ^haveg/employer/([0-9]+)/?(.*) haveg/employer.php?id=$1 

,只有當我鍵入http://localhost/haveg/employer/7003/the-message-title,但我想在這裏到達後,我點擊打開的頁面錨點。

謝謝。

回答

2

我想這是你想要的東西:

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^haveg/employer/([0-9]+){1,5}/?(.*) haveg/employer.php?id=$1&title=$2 [L,NC] 

你的錨就必須建立像:

<a href="/haveg/employer/7003/the-message-title">employer</a> 
+0

這很好用。 – shaikh 2012-01-31 07:10:34

+0

我不太明白。該代碼不起作用,然後他告訴你改變鏈接,所以你不需要重寫? – Tiggerito 2012-01-31 18:40:18

+0

該鏈接需要匹配URI,這是他必須更改其錨點的原因。重寫的作品,不知道你爲什麼說它不 – Jeremy 2012-01-31 18:48:44

0
RewriteCond %{QUERY_STRING} ^id=([^&]*)\&title=([^&]*)$ 
RewriteRule ^index.php /employer/%1/%2? [L,R=301] 
+0

你能解釋一下嗎?在我的情況下沒有index.php。 – shaikh 2012-01-31 07:16:19

+0

顯然UTF-8字符集 – 2012-01-31 16:56:49

+0

顯然我誤解了你。我以爲你需要點擊鏈接後,使用url params跳轉到以斜線分隔的參數頁面。 Index.php這裏並不重要,它只是一個例子,不是生產就緒的解決方案,不是嗎? – 2012-02-01 11:56:06