2015-11-18 90 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