的.htaccess和mod_rewrite的帮助 [英] .htaccess and mod_rewrite help

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

问题描述

使用mod_rewrite,我怎么可以把网址遵循这个模式是:

Using mod_rewrite, how could I turn URLs that follow this pattern:

http://example.com/index.php?id=14

进入该模式:

http://example.com/14/

推荐答案

当我想到你,而要改写请求 /&LT; ID&GT; / 内部以 /index.php?id=<ID> ,试试这个:

As I think that you rather want to rewrite requests to /<ID>/ internally to /index.php?id=<ID>, try this:

RewriteRule ^(\d+)/$ index.php?id=$1

但如果你真的想要请求重定向到 /index.php?id=<ID> 内部以 /&LT; ID&GT; /

RewriteCond %{QUERY_STRING} (^|&)id=(\d+)(&|$)
RewriteRule ^index\.php$ /%2/? [R]

如果你想preserve其他可能的URL参数:

And if you want to preserve possible other URL arguments:

RewriteCond %{QUERY_STRING} ^(([^&]*&+)*)id=(\d+)(&+(.*))?$
RewriteRule ^index\.php$ /%3/?%2%5 [R]

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

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