简体   繁体   English

添加新的重写规则时遇到麻烦

[英]Having some trouble adding a new rewrite rule

First of all, ModRewrite is a blind spot for me, I'm completely clueless when it comes to simplifying URLS, so bear with me. 首先,ModRewrite对我来说是一个盲点,在简化URLS方面我一无所知,所以请多多包涵。

Right, basically I've inherited a CMS from a colleague of mine which I use quite often. 是的,基本上我是从我的一位同事那里继承的CMS,我经常使用它。 It's a great framework and very useful for what I'm doing right now. 这是一个很好的框架,对于我现在正在做的事情非常有用。

My client wants a list of towns on their site, the data of which I've been provided with. 我的客户希望在其站点上列出城镇,并提供了我的数据。 I've added them all in and every town is called based on the ID. 我已经将它们全部添加进去,每个城镇都根据ID进行调用。 Simple, yep! 简单,是的!

The URL currently looks like town.html?tID=64 but I want it to read something like town/manchester.html 该URL当前看起来像town.html?tID = 64,但我希望它读取的内容类似于town / manchester.html

So far, my htaccess looks like: 到目前为止,我的htaccess看起来像:

RewriteEngine On
RewriteRule ^town/([^/]*)-([0-9]+)\.html$ town.html?tID=$2&tN=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php [L]

I added the &tN so I could pass the town name through. 我添加了&tN,以便可以传递城镇名称。

Nothing happens though, which is the most annoying part about it all. 但是什么也没发生,这是所有事情中最令人讨厌的部分。

Can anyone point me in the right direction? 谁能指出我正确的方向? I'm such a numpty when it comes to modrewrite stuff. 关于modrewrite的东西,我真是个傻瓜。

Tom 汤姆

here is your rewrite rule; 这是您的重写规则;

RewriteRule ^town/([^/]*)-([0-9]+)\.html$ town.html?tID=$2&tN=$1 [L]

this rewrite rule rewrites URLs ONLY if they are something similar to: town/manchester-64.html If it's not working , then your URL is NOT like that. 该重写规则在URL类似于以下内容town/manchester-64.html重写URL: town/manchester-64.html如果不起作用,则您的URL 不是那样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM