pretty网址的.htaccess [英] Pretty URLs with .htaccess

查看:183
本文介绍了pretty网址的.htaccess的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网址 HTTP://localhost/index.php用户= 1 ?。当我添加此的.htaccess 文件

I have a URL http://localhost/index.php?user=1. When I add this .htaccess file

Options +FollowSymLinks
RewriteEngine On

RewriteRule ^user/(.*)$ ./index.php?user=$1

我现在被允许使用的http://本地主机/用户/ 1 链接。但如何对 HTTP://localhost/index.php用户= 1&安培;行动=更新我怎样才能把它变成的http://本地主机/用户/ 1 /更新

I will be now allowed to use http://localhost/user/1 link. But how about http://localhost/index.php?user=1&action=update how can I make it into http://localhost/user/1/update ?

另外我怎样才能让这个网址的http://本地主机/用户/添加
谢谢。对不起,我是比较新的的.htaccess

Also how can I make this url http://localhost/user/add ? Thanks. Sorry I am relatively new to .htaccess.

推荐答案

感谢您的想法@denoise和@mogosselin。另外随着@stslavik您指出我的一些code例子的缺点。

Thanks for the idea @denoise and @mogosselin. Also with @stslavik for pointing out some of the drawback of my code example.

下面是我如何做到这一点:

Here's how I do it:

Options +FollowSymLinks
RewriteEngine On

RewriteRule ^user/([0-9]*)/([a-z]*)$ ./index.php?user=$1&action=$2
RewriteRule ^user/([a-z]*)$ ./index.php?user&action=$1

使用的var_dump($ _ GET); 链接本地主机/用户/ 1234 /更新

array (size=2)
  'user' => string '1234' (length=4)
  'action' => string 'update' (length=3)

,而本地主机/用户/添加

array (size=2)
  'user' => string '' (length=4)
  'action' => string 'update' (length=3)

这是我的目标。我只想做只用PHP引擎盖下的其他东西。

which is my goal. I will just only do other stuffs under the hood with PHP.

这篇关于pretty网址的.htaccess的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆