当前位置: 动力学知识库 > 问答 > 编程问答 >

.htaccess mod-rewrite question

问题描述:

hey there, i have quite some issues with the mode rewrite here is what i use :

RewriteEngine On

RewriteRule ^([^/]*)/([^/]*)$ /creatii.php?creatie_thumb=$2&user=$1 [L]

RewriteRule ^([^/]*)/$ /creatiiuser.php?user=$1

i would like this link :

http://creatii.artcrew.ro/creatii.php?creatie_thumb=creatie19&user=dee-dee

to look:

like http://creatii.artcrew.ro/dee-dee/creatie19

well this is fine, it works, no problems with it but i want to make a rule for another link

http://creatii.artcrew.ro/categorii.php?numecat=poetry&numesubcat=satire

to look like

http://creatii.artcrew.ro/poetry/satire

how can i do this? what rules must i use?

currently if i access http://creatii.artcrew.ro/poetry/satire

it access the link : http://creatii.artcrew.ro/creatii.php?creatie_thumb=satire&user=poetry

how can i make both links(the first one and the second one) work?

one more thing, i want this link : http://creatii.artcrew.ro/creatiiuser.php?user=Dan to look like http://creatii.artcrew.ro/Dan or if that does not work http://creatii.artcrew.ro/user/Dan

how can i do that?

can anyone help me?

thanks in advance

网友答案:

Given the URL http://creatii.artcrew.ro/X/Y, how is mod_rewrite supposed to know whether X and Y are creatie_thumb and user values or numecat and numesubcat values?

You need to add something to the URL to differentiate these cases.

For example:

  • http://creatii.artcrew.ro/user/dee-dee
  • http://creatii.artcrew.ro/user/dee-dee/creatie19
  • http://creatii.artcrew.ro/cat/poetry/satire
    RewriteEngine On
    RewriteRule ^user/([^/]*)/([^/]*)$ /creatii.php?creatie_thumb=$2&user=$1 [L]
    RewriteRule ^user/([^/]*)/$ /creatiiuser.php?user=$1 [L]
    RewriteRule ^cat/([^/]*)/([^/]*)$ /creatii.php?numecat=$1&numesubcat=$2 [L]
网友答案:

Maybe you're too much generic with your rules and you got conflicts.

Try to map this urls

http://creatii.artcrew.ro/creatii/dee-dee/creatie1 http://creatii.artcrew.ro/categorii/poetry/satire

Starting from those sample you can easily map your urls with no conflict on rules

RewriteEngine On
RewriteRule ^creaati/([^/]*)/([^/]*)$ /creatii.php?creatie_thumb=$2&user=$1 [L]
RewriteRule ^categorii/([^/]*)/([^/]*)$ /categorii.php?numecat=$1&numesubcat=$2 [L]

Do some tries :D

分享给朋友:
您可能感兴趣的文章:
随机阅读: