Rewriting URL on Apache [Not finished]

Resume

It’s very common to do the URL rewriting while we are developing a site. Thus, many people wants to do this to make their site more beautiful. However, some of the tutorials are too complicated. This passage will tell you how to rewrite URL on Apache as easy as possible.


.htaccess

For instance, if we have blog.php in the directory blog. And we want to redirect a URL like http://example.com/blog/123 to http://example.com/blog/blog.php?id=123. Then we need to do the URL rewriting.

/blog
    ./blog.php

First of all, create a file called .htaccess in the directory that you want to rewrite.
Then, if you haven’t enabled the URL rewriting generally, write RewriteEngine On in your .htaccess file to enable URL rewriting.


Create rules

Then, in our .htaccess file, just simply type RewriteRule ^blog/([0-9]+) blog.php?id=$1.
Some readers may already know that the ([0-9]+) is the regular expression which means that we are allowed to define what we want to accept in the URL.
Moreover, $1 means we take the first regexp as a variable.

TO BE CONTINUE…

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值