使用mod_rewrite工作不更改显示的URL结构 [英] Change Displayed URL Structure using mod_rewrite NOT Working

查看:161
本文介绍了使用mod_rewrite工作不更改显示的URL结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要改变显示的客户端的URL的结构。我不是太熟练使用正则表达式和编码的.htaccess文件。基本上,我有一个结构,它看起来是这样的:

I need to change the structure of the displayed client-side URL. I'm not too skilled using regex and coding for the .htaccess file. Basically, I have a structure that looks something like:

http://www.example.com/catalog/index.php?cat=lt&sec=lt1-1&id=nmlt10.  

我想这显示在地址栏中显示为:

I would like this to be displayed in the address bar as:

http://www.example.com/catalog/lt/lt1-1/nmlt10.  

这就是我想出了,但它没有任何效果:

This is what I came up with, but it has had no effect:

RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)/([^/]*)\$ /catalog/index.php?cat=$1&sec=$2&id=$3 [L]

我测试并删除任​​何其他规则.htaccess文件,以确保没有被被覆盖。我是一个共享的主机Apache服务器上,并且知道mod_rewrite的启用,因为我用它来重写非www到www的网址。我没有收到500错误信息,我只是不任何通知而变动的。我不知道我要去哪里错在这里,所以希望有人能在正确的方向指向我。

I tested and removed any other rules in the .htaccess file to ensure nothing was being overwritten. I'm on a shared hosting apache server, and know that mod_rewrite is enabled, because I use it to rewrite non-www to www urls. I don't receive and 500 error messages, I just do not notice any change at all. I'm not sure where I'm going wrong here, so hopefully someone can point me in the right direction.

推荐答案

终于找到了工作的解决方案:

Finally found a solution that worked:

RewriteEngine On
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ index.php?cat=$1&sec=$2&id=$3 [QSA,L]

鸭preciate LazyOne的反应让我在正确的轨道;然而,当使用

Appreciate LazyOne's response to get me on the right track; however, when using:

RewriteEngine On
RewriteRule ^([^/]+)/([^/]+)/([^/]+)$ index.php?cat=$1&sec=$2&id=$3 [QSA,L]

我无法下那些已经放置在网站的链接,它对待不同的目录中的变量,例如,浏览图像或文件时,说:

I wasn't able to following links that were already placed on the site, it treated different directories as the variables, for example, when browsing to an image or file, say:

folder/folder/image.png

这将抢文件夹 - 文件夹 - 和形象为变量。我能明白为什么这是怎么回事,如果任何人有不同的解决方案或解释,请让我知道,我总是愿意学习。

It would grab "folder" - "folder" - and "image" as the variables. I can see why that was happening, if anyone has a different solution or an explanation, please let me know, I'm always willing to learn.

这篇关于使用mod_rewrite工作不更改显示的URL结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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