Mod_rewrite动态网址 [英] Mod_rewrite dynamic URLS

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

问题描述

我想要重写的示例

www.website.com/index.php
www.website.com

www.website.com/index.php
www.website.com

www.website.com/index.php?page=first
www.website.com/first

www.website.com/index.php?page=first
www.website.com/first

而且

www.website.com/index.php?category=cat&page=second
www.website.com/cat/second

www.website.com/index.php?category=cat&page=second
www.website.com/cat/second

非常感谢

推荐答案

100%确定要以这种方式进行重写吗?似乎这与通常的安装重写方式相反.查看 此问题 第一个答案 ,以了解我的意思.

Are you 100% sure you want to do the rewriting this way? It seems like this is backwards to how you usually setup rewrites. Check out this question and the first answer to see what I mean.

我要大步走出去,问也许您想让浏览器中的URL 像这样:

I'm going to go out on a limb and ask that maybe you want to have the URLs in the browser look like:

http://www.website.com/cat/second

,并且您希望您的 php应用程序然后接收:

and that you want your php application to then receive:

http://www.website.com/index.php?category=cat&page=second

在这种情况下,您想要类似的东西

In which case you would want something like

 <IfModule mod_rewrite.c>
RewriteEngine On
# note this first rewrite would be redundant in 99.999% of cases, apache expects to serve index.php for the /
RewriteRule ^/$ /index.php [last]
RewriteRule ^(.*)$ /index.php?page=$1 [last]
RewriteRule ^(.*)/(.*)$ /index.php?category=$1&page=$2 [nocase,last]
</IfModule>

如果我错了,那么Ivan c00kiemon5ter V Kanak的回答将对您有用.然后,我也对您要进行防重写"的情况感到好奇:)

If I'm wrong, then Ivan c00kiemon5ter V Kanak's answer will do you right. And I'm then also curious about what kind of situation you are in where you want to do "anti-rewriting" :)

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

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