创建htaccess的动态网址 [英] Creating dynamic URLs in htaccess

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

问题描述

我试图写一个.htaccess文件,这将使我的网址更具吸引力的搜索引擎。我知道基本上是如何做到这一点,但我不知道我怎么可以动态地做到这一点。

I'm trying to write an .htaccess file that will make my URLs more attractive to search engines. I know basically how to do this, but I'm wondering how I could do this dynamically.

我的URL一般是这样的:

My URL generally looks like:

view.php?mode=prod&id=1234

我想要做的就是把ID从URL,做一个数据库查询,然后把从数据库标题返回到的URL。是这样的:

What I'd like to do is take the id from the url, do a database query, then put the title returned from the DB into the url. something like:

/products/This-is-the-product-title

我知道有些人已经做到了这一点与phpBB论坛的网址和主题,和我试图跟踪code到它替换为新标题字符串URL实际的URL,但没有运气。

I know that some people have accomplished this with phpbb forum URLs and topics, and i've tried to track the code down to where it replaces the actual URL with the new title string URL, but no luck.

我知道我可以只用ID重写URL如:

I know I can rewrite the URL with just the id like:

RewriteRule ^view\.php?mode=prod&id=([0-9]+) /products/$1/

有没有办法在PHP覆盖URL显示?

Is there a way in PHP to overwrite the URL displayed?

推荐答案

目前,你想知道如何转换你的丑URL(如 /view.php?mode=prod&id=1234 )到pretty的网址(例如: /产品/产品称号)。开始倒过来看这个。

At the moment you're wondering how to convert your ugly URL (e.g. /view.php?mode=prod&id=1234) into a pretty URL (e.g. /products/product-title). Start looking at this the other way around.

您需要的是有人键入 /产品/产品称号来真正带他们去,可以通过何种交往访问的页面?模式= PROD和放大器; ID = 1234

What you want is someone typing /products/product-title to actually take them to the page that can be accessed by /view.php?mode=prod&id=1234.

即。您的规则可以如下:

i.e. your rule could be as follows:

RewriteRule ^products/([A-Za-z0-9-])/?$ /view.php?mode=prod&title=$1

那么在view.php做的基础上,标题查找找到 ID 。然后再进行正常。

Then in view.php do a lookup based on the title to find the id. Then carry on as normal.

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

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