我应该对我的网站 URL 使用 mod_rewrite 吗?
我的网站目前处理这样的URL......
/?p=home
/?p=profile&userid=1
/?p=users.online
/?p=users.online&page=23
/?p=mail.inbox
/?p=mail.inbox&page=12
等等,可能至少有120-150个不同的页面,在我的网站上,一个页面是这样构建的,
index.php包括一个主配置文件,然后包含函数/类文件到其中
index.php 然后包含一个头文件
index.php 然后包含来自 url ?p=pagename
的页面文件 index.php 然后包含一个页脚文件
这就是我网站上的每个页面的编译方式,通过这样的索引页面,我一直在考虑/思考清理URL 是因为我现在正在重写/重组我的大部分网站代码,如果我打算这样做的话,现在是执行此操作的最佳时机。我的意思是使用 mod-rewrite 来清理 URL,这样上面的 URL 结构就会看起来像这样......
/home
/users/1 //user ID might switch to use username as well
/users/online
/users/online/23 or /users/online/page/23
/mail/inbox
/mail/inbox/12
所以首先这样做有什么缺点吗?它是否会创建更多的处理工作,因为它使用的是mod_重写?
另外,以我上面显示的格式编写正则表达式或匹配文件名所需的任何内容是否会很困难,我只列出了其中几个页面,但至少有 100 个不同的 URL 页面,我有博客、公告、论坛,各种东西
My site currently handles URL's like this...
/?p=home
/?p=profile&userid=1
/?p=users.online
/?p=users.online&page=23
/?p=mail.inbox
/?p=mail.inbox&page=12
... and so on, there is probably at least 120-150 different pages, on my site a page is built like this,
index.php includes a main config file which then includes function/class files into it
index.php then includes a header file
index.php then includes the page file which is from the url ?p=pagename
index.php then includes a footer file
That is how every page on my site is compiled, through the index page like that and I have been considering/thinking about cleanning up the URL's as I am re-writing/restructuring most of my sites code right now, it's the perfect time to do it if I am going to do it. What I mean by cleanning up the URL's is using mod-rewrite so the URL structure above would look like this instead...
/home
/users/1 //user ID might switch to use username as well
/users/online
/users/online/23 or /users/online/page/23
/mail/inbox
/mail/inbox/12
So first of all is there any downfalls to doing this, does it create a lot more processing work since it is using mod_rewrite?
Also would it be hard to write the regex or whatever is needed to match the file names in the format that I show above, I listed only a few of the pages but there would be at least 100 different URL pages I have blogs, bulletins, forums, all kinds of stuff
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
绝对地。这是 Apache 的主要目的之一,因此它被设计为非常高效地完成此任务。事实上,我希望您使用该方法。
使用该 URL 结构没有缺点,而且有很多优点。大胆试试吧!
Absolutely. That's one of Apache's main purposes, so it's been designed to do it very efficiently. In fact, I'd emplore you to use that method.
There are no downfalls, and a ton of advantages to using that URL structure. Go for it!