问题描述:

Possible Duplicate:

.htacces to create friendly URLs. Help needed

I am new to url rewritting so here's my query

I have a site http://www.mysite.com/ichat now if a request comes like `http://www.mysite.com/ichat/a2b35'

I want to redirect it to a php file in my server in the ichat directory as under

http://www.mysite.com/ichat/chat.php?chatid=a2b35

but if the url is like this

`http://www.mysite.com/ichat/special/a2b35'

i want to redirect it to

http://www.mysite.com/ichat/chat.php?special=yes&chatid=a2b35

the chatid will be alphanumeric without special characters. Is this redirection possible or i need a physical special folder for this to work?

网友答案:

Sure, just take advantage of the fact that rewrites are ordered in evaluation:

RewriteRule ^/ichat/special/(.+) /chat.php?special=yes&chatid=$1 [L]
RewriteRule ^/ichat/(.+) /chat.php?chatid=$1 [L]

The [L] means that rule evaluation will stop at the rule if it matches it, so any /ichat/special/ url will get caught by the first rule, and the other /ichat/ urls will get caught by the second.

网友答案:

Based on above code , below is sample code when page can be redirected on ichat in url

RewriteEngine on
RewriteCond %{REQUEST_URI} ^/~ichat/ [OR]
RewriteRule ^(.*)$ http://www.mysite.com/ichat/chat.php?chatid=$1 [R,L]

Put the above code in .htaccess file.

May this would help you.

相关阅读:
Top