我应该对我的网站 URL 使用 mod_rewrite 吗?

发布于 2024-08-04 20:16:04 字数 1002 浏览 4 评论 0原文

我的网站目前处理这样的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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

林空鹿饮溪 2024-08-11 20:16:04

绝对地。这是 Apache 的主要目的之一,因此它被设计为非常高效地完成此任务。事实上,我希望您使用该方法。

  1. 它为访问者提供更清晰的 URL
  2. 对于 SEO 来说非常棒
  3. 它使网站更加专业
  4. 如果用户试图查找某个页面而无需实际遍历您的网站找到它,则可以更轻松地猜测 URL。

使用该 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.

  1. It makes cleaner URLs for visitors
  2. It's fantastic for SEO
  3. It makes the website more professional
  4. It makes it easier for users to guess URLs if they are trying to find a certain page without actually traversing through your site ti find it.

There are no downfalls, and a ton of advantages to using that URL structure. Go for it!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文