I'm trying to rew开发者_StackOverflowrite my URLs to be more SEO friendly, and I'm doing this in my .htaccess file using the following code:
RewriteEngine On
RewriteRule blog/(.*)/$ blog/index.php?&link=$1 [NC]
RewriteRule ^/*(.+/)?([^.]*[^/])$ http://%{HTTP_HOST}/$1$2/ [L,R=301]
That code allows me to rewrite http://example.com/blog/index.php?link=22 into http://example.com/blog/page-title/
The only problem here, is that I'm trying to get it to work without the ending slash (/). I've tried removing it in the third line of the .htaccess code (right fater the $2), but that just breaks everything and the rewrite doesn't work at all.
Any help is greatly appreciated.
Try now, both with or without slash should work.
RewriteEngine On
RewriteRule blog/(.*)/?$ blog/index.php?&link=$1 [NC]
RewriteRule ^/*(.+/)?([^.]*[^/])$ http://%{HTTP_HOST}/$1$2 [L,R=301]
精彩评论