简体   繁体   中英

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]

where 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.

您需要这样的东西。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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