开发者

Rewrite url in .htaccess [duplicate]

This question already has an answer here: Closed 11 years ago.

Possible Duplicate:

.htaccess url rewrite

How 开发者_JAVA百科can I Rewrite URL in .htaccess file

from

http://example.com/blogs/123/2/blog-title-goes-here

to

http://example.com/blogs/blog-title-goes-here

?


I don't think you can rewrite to a dynamic URL - I may be wrong however, find out what the original URL rewrites too then edit your question to let us know then I can help


If you mean that you type http://example.com/blogs/123/2/blog-title-goes-here the browser, you got served this page http://example.com/blogs/blog-title-goes-here then

RewriteRule ^blogs/[0-9]+/[0-9]+/(.*) /blogs/$1 [R,L] #Or just [L] if you don't want a redirect but a simple rewrite. 

If you mean that the client types http://example.com/blogs/blog-title-goes-here and gets redirected to http://example.com/blogs/123/2/blog-title-goes-here there are no ways to do it with mod_rewrite since it can't just guess the number 123 an 2 (unless they are static numbers)


You could do something like this:

RewriteRule ^blogs/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)?$ /blogs/article/$3 [NC,L]

Edited: since I could test now :)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜