创建漂亮的网址 [英] creating nice looking URLs
问题描述
我试图让一个友好的URL看我的丑陋的网址。
MOD
目录包含的index.php
和 user.php的
文件。该的index.php
只有一些链接的各种格式,给用户的页面。
路径 MOD
目录:的http://本地主机/ MOD /
在这个时候用户的网址是这样的。
的http://localhost/mod/user.php ID =瑞奇等。
我需要那个丑陋的一个很好的对望一眼这样的事情。
的http://本地主机/ MOD /用户/瑞奇
我想在我的htaccess的文件,这是code,到目前为止在该文件中。
#开启重写
RewriteEngine叙述上
#重写用户网址
#输入:用户/姓名/
#输出:user.php的ID = NAME
重写规则^用户/([A-Z] +)/ $ user.php的?ID = $ 1
这是不是为我工作。希望有人能帮助我。 谢谢你。
重写规则^用户/([A-ZA-Z] +)/ $ user.php的?ID = $ 1 [NC,L]
行的状态结束,例[NC,L]
不敏感您也可以只使用\ W匹配所有文字字符(非数字)
重写规则^用户/(\ w +)/ $ user.php的?ID = $ 1 [NC,L]
下面是一个备忘单的正则表达式: HTTP://www.regular-ex$p$pssions.info/reference.html
I am trying to make a friendly looking URLs for my ugly URLs.
mod
directory contains an index.php
and a user.php
file. The index.php
only has some links, of various formats, to the user page.
path to mod
directory like this : http://localhost/mod/
at this time user's urls something like this..
http://localhost/mod/user.php?id=Ricky etc..
I need to make that ugly one to nice looking one something like this..
http://localhost/mod/user/Ricky
I tried it in my htaccess file, and this is code so far in that file.
# Enable Rewriting
RewriteEngine on
# Rewrite user URLs
# Input: user/NAME/
# Output: user.php?id=NAME
RewriteRule ^user/([a-z]+)/?$ user.php?id=$1
This is not working for me. Hope someone will help me. Thank you.
RewriteRule ^user/([A-Za-z]+)/?$ user.php?id=$1 [NC,L]
State end of line and case insensitive with [NC,L]
You can also just use \w to match all text chars (non digit)
RewriteRule ^user/(\w+)/?$ user.php?id=$1 [NC,L]
Here's a cheat sheet for regex: http://www.regular-expressions.info/reference.html
这篇关于创建漂亮的网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!