2015-11-18 89 views
0

我可以得到這個幫助:創建htaccess的一個固定鏈接

我在谷歌網站管理員工具看斷開鏈接是這樣的: test.php的T =測試%20title

test.php的頁面刪除,現在我用index.php而不是test.php

所以我需要用htaccess重新編寫url。我怎樣才能做到這一點?

http://www.domain.com/test.php?t=test%20title 鏈接改變 http://www.domain.com/t/test-title/http://www.domain.com/index.php?t=test%20title

我也嘗試這些選項但不工作的:

ReWriteRule ^test.php?t=(.*)$ index.php?t=$1 
ReWriteRule ^test.php?t=([0-9a-z]+)$ index.php?t=$1 
ReWriteRule ^test\.php\?t=(.*)$ index.php?t=$1 
ReWriteRule ^test\.php\?t=([0-9a-z]+)$ index.php?t=$1 

有可能創建永久使用htaccess的這個? http://www.domain.com/t/test-title/

回答

0

查詢字符串不是RewriteRule指令中的匹配項的一部分,請使用%{THE_REQUEST}變量來匹配查詢字符串。

試試這個在您的htaccess:

RewriteEngine on 

RewriteCond %{THE_REQUEST} /index\.php\?t=([^\s]+)\s*([^\s&]+)\sHTTP/1.1 [NC] 
RewriteRule^/t/%1-%2? [NC,L,R] 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^t/([^-]+)-([^/]+)/?$ /index.php?t=$1%20$2 [NC,L] 
+0

感謝您的回覆,我很抱歉我遲到的答覆。我現在嘗試了,但url更改爲這樣:http://www.domainname.com/home/hostusername/public_html/t/test-title-HTTP/1.1我該怎麼做? http://www.domainname.com/t/test-title – webmaster

+0

@Webmaster我編輯了這個答案,問題是重寫目標中的相對路徑,我已將其更改爲絕對路徑。 – starkeen

+0

謝謝你的回答。現在url像這樣變化:http://www.domainname.com/t/test-title-HTTP/1.1如何從url中移除-HTTP/1.1?我需要這樣的:http://www.domainname.com/t/test-title/ – webmaster