.htaccess :日期范围帮助
嗨,我的网址是这样的 http://www.mysite.come/events.php?eid=10
活动开始日期是 01-07-2011
活动名称:夏日之旅
我想将上面的 URL 显示为类似 http://www.mysite.com/events/01/07/2011 /summer-trip
这有意义吗?
我将感谢您的所有回答,请尽快提供帮助。
谢谢
Hi my URL is something like
http://www.mysite.come/events.php?eid=10
Event starting date is 01-07-2011
Event name : summer trip
I want to display the above URL to be like
http://www.mysite.com/events/01/07/2011/summer-trip
Does this make sens!?
I will appreciate all your answers, please help as soon as possible.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试如下操作:
这是一个包罗万象的重定向 - 如果不存在与请求匹配的文件,则该请求将使用原始 url 传递到 index.php。 (大多数框架、wordpress 等都是这样做的)
然后你将在 index.php 中获得 $_GET['url'] ,你可以在 php 中解析它并执行任何需要执行的操作来检查/加载相关内容。
请注意,您需要确保在 PHP 中实现 404 错误 - 因为 apache 永远不会再出现 404 错误。
Try something like:
It's a catch all redirect - if a file doesn't exist to match a request, the request is passed to index.php with the original url. (it's how most of the frameworks, wordpress etc do it)
Then you will have $_GET['url'] available in index.php, which you can parse in php and do whatever needs doing to check for/load relevant content.
Note that you need to ensure you implement a 404 error in PHP here - as apache will never 404 itself any more.
如果您只想以友好的格式发送日期,这是一个非常简单的重定向:
但是,mod_rewrite 不会发挥作用。无法从
01/01/2011/summer-trip
获取10
。编辑:我想我不应该从字面上理解这个问题并提供一些提示。如果您想通过友好的字符串链接事件,则需要进行一些内部更改:
向数据库中的事件表添加一个新列并使其唯一(大多数 DBMS 允许创建唯一索引)。该新列(我们称之为
url_title
)将保存友好字符串。调整您的 PHP 脚本,使其采用
url_title
作为参数,而不是数字键。你的 mod_rewrite 规则将是这样的:
If you just want to send the date in a friendly format, it's quite a simple redirection:
However, mod_rewrite won't do magic. There's no way to obtain
10
from01/01/2011/summer-trip
.Edit: I guess I should not take the question literally and provide some hints. If you want to link events by a friendly string, you need to do a couple of internal changes:
Add a new column to the events table in your database and make it unique (most DBMS allow to create unique indexes). That new column (let's call it
url_title
) will hold the friendly string.Adjust your PHP script so it takes the
url_title
as argument, rather than the numeric key.And your mod_rewrite rule will be something like this: