简体   繁体   English

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

[英]Issue with Rewrite Rule in .htaccess file

I was about to convert my webpage url into seo friendly. 我打算将我的网页网址转换为seo友好。 My url link is like follows 我的网址链接如下

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

Now i want to convert this into seo friendly url, which could be 现在我想将其转换为seo友好的网址,这可能是

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

Something like above. 像上面的东西。 I used 我用了

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

Rewrite rule in htaccess file. 在htaccess文件中重写规则。 But still the url stays same as older one. 但网址仍然与旧网址相同。 Anyone can help me to fix this issue??? 任何人都可以帮助我解决此问题???

You need 1 more 301 rule before this rule for external redirection: 在此规则进行外部重定向之前,您还需要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]

As commented by Justin and other folks it is better to change your links to /partners-id-123.html . 正如Justin和其他人所评论的那样,最好将您的链接更改为/partners-id-123.html However for links already cached by search engines will be taken care by first rule here which will 301 redirect: 但是,对于已经由搜索引擎缓存的链接,请遵循此处的第一个规则,它将进行301重定向:

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

Please try like below: 请尝试如下:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM