在PHP重写URL以mod_rewrite的 [英] Rewrite URL in PHP with mod_rewrite
本文介绍了在PHP重写URL以mod_rewrite的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Web服务器就是Apache。我想重写URL,这样用户就不会知道实际的目录。例如: 原网址:
http://www.example.com/en/piecework/piecework.php?piecework_id=11
预计网址:
http://piecework.example.com/en/11
如何使用实现它 mod_rewrite的?
解决方案
我建议以下规则:
的RewriteCond%{HTTP_HOST} ^(?!万维网)([^。] +)\。mydomainname \ .COM $ [NC]
重写规则^(W +)/(\ d +)$ /$1/%1/%1.php?%1_id=$2 [L]
The web server is Apache. I want to rewrite URL so a user won't know the actual directory. For example: The original URL:
http://www.example.com/en/piecework/piecework.php?piecework_id=11
Expected URL:
http://piecework.example.com/en/11
How to achieve it with mod_rewrite?
解决方案
I would suggest the following rule:
RewriteCond %{HTTP_HOST} ^(?!www)([^.]+)\.mydomainname\.com$ [NC]
RewriteRule ^(w+)/(\d+)$ /$1/%1/%1.php?%1_id=$2 [L]
这篇关于在PHP重写URL以mod_rewrite的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文