删除带有 mod_rewrite 和 SEO 问题的 .php 扩展名
我正在尝试使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
听起来 MultiViews 是比重写 URL 更好的解决方案。只需将其放入您的
.htaccess
中即可。本质上,如果我输入 stackoverflow.com/pages,它会首先查找名为pages
的目录,如果找不到,则查找一个文件。然后,您可以使用stackoverflow.com/pages/view/some/page
,其中/view/some/page
是查询。编辑要获取
/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 instackoverflow.com/pages
it will first look for a directory namedpages
, if it can't find it, a file. You can then havestackoverflow.com/pages/view/some/page
where/view/some/page
is the query.Edit To get the
/view/some/page/
use$_SERVER['PATH_INFO'];
你一定要看看 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