开发者

Mod-Rewrite for dynamic URLs

开发者 https://www.devze.com 2023-02-19 15:45 出处:网络
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:

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]
0

精彩评论

暂无评论...
验证码 换一张
取 消