Apache 友好网址 [英] Apache friendly urls
问题描述
我有一个用 PHP 编写并在 Apache 上运行的小型 CMS 系统.此 CMS 系统使用/生成的 URL 格式为:
I've got a small CMS system written in PHP and running on Apache. The format of the URLs this CMS system uses/generates is:
/display.php?PageID=xxx 其中 xxx 只是一些整数.如您所见,这些网址对用户和搜索引擎都不是很友好.
/display.php?PageID=xxx where xxx is just some integer number. As you can see, those URLs are not very friendly, neither for users nor search engines.
我相信使用 mod_rewrite(或类似的东西)和 .htaccess 文件我应该能够配置 Apache 进行 URL 重写.我之前搜索过有关这方面的信息,但我没有找到任何简单的方法来做到这一点,它总是涉及到我不太熟悉的正则表达式.
I believe that using mod_rewrite (or something like that) and .htaccess files I should be able to configure Apache for URL-rewriting. I have searched for information about this before but I did not find any easy method to do this, it always involved messing with regular expressions, which I'm not very familiar with.
由于所讨论的网站非常简单而且很小,只有 5-10 个不同的页面,我真的希望能够对配置进行硬编码,而无需任何特殊规则或正则表达式.
Since the website in question is really simple and small, just 5-10 different pages, I would really like to be able to just hard-code the configuration, without any special rules or regexps.
我只想将一个友好的 URL 映射到一个实际的 URL,可能是这样的:
I'd just like to map a friendly URL to an actual URL, perhaps like this:
/about = /display.php?PageID=44
/products = /display.php?PageID=34
等
是否可以像这样以基本方式配置 mod_rewrite 插件?
Is it possible to configure the mod_rewrite plugin in a basic way like this?
有人能解释一下最简单的方法吗?像小时候一样向我解释:-)
Could someone explain the easiest method to do this? Explain it to me as if I was a child :-)
提前致谢!
推荐答案
把类似的东西放好
RewriteEngine on
RewriteRule ^about$ ./display.php?PageID=44
RewriteRule ^products$ ./display.php?PageID=34
在您的 .htaccess
文件中,我认为应该没什么大不了的...
in your .htaccess
-file shouldn't be the big deal I think...
这篇关于Apache 友好网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!