删除带有 mod_rewrite 和 SEO 问题的 .php 扩展名

发布于 2024-09-19 01:35:53 字数 368 浏览 4 评论 0原文

我正在尝试使用 modrewrite 将我的网址从 /foo.php 更改为 /foo ,并从 /foo.php?lang=en 更改为 /en/foo 。我遇到的问题是,我认为我需要使用 301 重定向将 .php-less 地址移动到 .php 地址,否则我的排名将分为这 2 个。但是如果我使用 [R=301] 地址栏中对 .php 的更改使我的漂亮网址努力毫无用处。我应该怎么办?

我四处寻找我能找到的任何问题\教程,但我无法完全理解 modrewrite。我遇到的主要问题是,如果我更改 .htaccess 文件,然后重新访问已经访问过的页面,新的 .htaccess 不起作用,但会以某种方式缓存旧结果,从而使纠正变得非常痛苦。你知道解决方法吗?

谢谢你,

木酱

I'm trying to use modrewrite to change my urls from /foo.php to /foo and from /foo.php?lang=en to /en/foo. The problem I have is that I think I need to use 301 redirect to move the .php-less address to the .php address, or else my ranking will be splitted among these 2. But if I use [R=301] the address in the bar changes to the .php one making my pretty url efforts quite useless. What should I do?

I've looked around for any question\tutorial i could find but I can't fully understand modrewrite. The main issue I have is that if I change my .htaccess file then revisit an already visited page the new .htaccess is not working but is somehow caching the old result making correction a real pain. Do you know a workaround?

Thank you,

Mokuchan

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

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

发布评论

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

评论(2

不羁少年 2024-09-26 01:35:53

听起来 MultiViews 是比重写 URL 更好的解决方案。只需将其放入您的 .htaccess 中即可。本质上,如果我输入 stackoverflow.com/pages,它会首先查找名为 pages 的目录,如果找不到,则查找一个文件。然后,您可以使用 stackoverflow.com/pages/view/some/page ,其中 /view/some/page 是查询。

Options Indexes FollowSymLinks Includes MultiViews

编辑要获取/view/some/page/,请使用$_SERVER['PATH_INFO'];

Sounds like MultiViews would be a better solution than rewriting the URL. Just put this in your .htaccess. What that will do is essentially, if i type in stackoverflow.com/pages it will first look for a directory named pages, if it can't find it, a file. You can then have stackoverflow.com/pages/view/some/page where /view/some/page is the query.

Options Indexes FollowSymLinks Includes MultiViews

Edit To get the /view/some/page/ use $_SERVER['PATH_INFO'];

非要怀念 2024-09-26 01:35:53

你一定要看看 Apache modul mod_rewrite 和重写 url 的一般思想。

http://httpd.apache.org/docs/2.0/mod/mod_rewrite。 html

You definitely must look at Apache modul mod_rewrite and general idea of rewriting urls.

http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html

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