开发者

Url Rewrite in a different way

I am used to rewriting links like this:

http://example.com/category/banking-jobs :: RewriteRule ^category/([^/]+)/$ category.php?id=$1 [L]

whe开发者_StackOverflowre category is fixed ie.a part of the url is fixed.

I realized am not good at rewrite at all when i ran into a rewrite with no fixed part eg.

http://example.com/year/month/post-name

this means that the year, month, post-name can b anything.

Please how can i go about this

EDIT:

i have another scenario i have another url structure (http://example.com/year/month/day) similar to: http://example.com/year/month/post-name

but they are meant to be handled seperately. how do i achieve it


Use placeholders ([^/]+) like in your original example.

      RewriteRule ^category/([^/]+)/$ category.php?id=$1 [L]
                      ^        ^
corresponds to        |        |
                      |        |
http://example.com/category/banking-jobs

So for an URL like:

 http://example.com/year/month/day/post-name

You would use:

 RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/$ category.php?$1,$2,$3

And anything that's in ( parenthesis ) will add another enumerated $4 which you then use in the rewriten filename as &param=$2 placeholder.


You need something like this.

RewriteRule ^(.+)/(.+)/(.+)/(.+)$ category.php?y=$1&m=$2&d=$3&post=$4 [L]
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜