Apache mod_rewrite VS. PHP路由?

发布于 2024-09-06 17:25:38 字数 495 浏览 2 评论 0原文

几天来,我一直在尝试制定一个简单的 mod_rewrite 规则来创建友好的 URL,我的网络主机启用了 mod_rewrite 但我无法让它工作。

接下来的所有问题均由我发布:

  1. .htacces 创建友好 URL
  2. 带有 .htaccess 的友好 URL
  3. .htacces 不起作用…

没有一个答案起作用,所以我现在想使用简单的 php 路由代替,我想知道两者之间是否存在很大的性能或 SEO 差异。如果有的话,也许你知道如何解决我的问题中发布的 mod_rewrite 问题。

谢谢。

for some days now I have been trying to make a simple mod_rewrite rule to create friendly URLs, my web host have mod_rewrite enabled but I just can't get it to work.

All the next questions where posted by me:

  1. .htacces to create friendly URLs
  2. Friendly URLs with .htaccess
  3. .htacces NOT working…

None of the answers worked, so I'm thinking now using simple php routing instead and I wanted to know if there is a big performance or SEO difference between the two. And if there is, maybe you know how to fix the mod_rewrite problems posted in my questions.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

宛菡 2024-09-13 17:25:38

如果您仅对 PHP 文件使用 PHP 路由,那么性能方面不会有问题:解释器无论如何都会启动,启动新进程,分配内存等。

但是如果您计划路由对图像等静态资源的请求和样式表,但是,在任何情况下都不要使用 PHP 路由。它过于消耗资源,而不是 PHP 的构建目的。

我想说 mod_rewrite 是更好、更精简的解决方案,值得尝试弄清楚。

If you're using PHP routing for PHP files only, it would be no problem performance-wise: The interpreter will get started anyway, a new process started, memory allocated etc.

But if you are planning to route requests for static resources like images and style sheets as well, however, don't use PHP routing under any circumstance. It's way too resource-intensive and not what PHP was built for.

I'd say mod_rewrite is the better, leaner solution and it's worth trying to figure it out.

呆头 2024-09-13 17:25:38

我更喜欢在请求的文件不存在时启动的路由,就像 Lighttpd 中的这样:

server.error-handler-404 = "/index.php"

如果您了解如何在 Apache 中执行此操作,您的脚本将更加跨 Web 服务器兼容,因为 .htaccess 中的 Apache 的 mod_rewrite 条件不会在 Lighttpd 上工作。

I prefer routing that kicks in when the requested file doesn't exist, like this in Lighttpd:

server.error-handler-404 = "/index.php"

Provided you find out how to do this in Apache, your script would be more cross webserver compatible, since Apache's mod_rewrite conditions in .htaccess won't work on Lighttpd.

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