.htaccess文件中的重写规则问题

时间:2014-02-05 12:53:16

标签: php .htaccess mod-rewrite

我准备将我的网页网址转换为seo友好版。我的网址链接如下

http://example.com/display.php?id=***

现在我想把它转换成seo友好的url,可能是

http://example.com/partners-id-***.html

像上面这样的东西。我用了

RewriteEngine On
RewriteRule ^partners-id-([^-]*)\.html$ /display.php?id=$1 [L]

重写htaccess文件中的规则。但仍然保持网址与旧网址相同。任何人都可以帮我解决这个问题???

2 个答案:

答案 0 :(得分:1)

在此规则之前,您需要再使用301规则进行外部重定向:

RewriteEngine On

RewriteCond %{THE_REQUEST} \s/+display\.php\?id=([^\s&]+) [NC]
RewriteRule ^ /partners-id-%1.html? [R=301,L]

RewriteRule ^partners-id-([^.]*)\.html$ /display.php?id=$1 [L,QSA]

Justin和其他人评论说,最好将链接更改为/partners-id-123.html。但是,对于已经由搜索引擎缓存的链接,将在第一个规则处理,这将是301重定向:

/display.php?id=1234 => /partners-id-1234.html

答案 1 :(得分:-1)

请尝试如下:

RewriteEngine On
RewriteRule ^([^/]*)\.html$ /display.php?id=$1 [L]
相关问题