apache - htaccess 美化 URL 需要加 301 重定向吗

标签 apache .htaccess mod-rewrite seo

我使用这个简单的规则从我网站的 URL 中删除 index.php:

RewriteRule ^.*$ ./index.php

因此 http://example.com/index.php/user/me 变成 http://example.com/user/me

我是否需要添加 [R=301] 以避免从 SEO 的角度来看“内容重复”问题?

最佳答案

您可以添加此规则来避免这种情况:

RewriteCond %{THE_REQUEST} \ /index\.php/([^\?\ ]*)
RewriteRule ^ /%1 [L,R=301]

它将把使用 /index.php 的请求重定向到没有的请求。然后,您已经拥有的规则将在内部重写 index.php。

关于apache - htaccess 美化 URL 需要加 301 重定向吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33111424/

相关文章:

.htaccess - HTTPS URL 中的 Codeigniter Index.php

azure - .htaccess If/Else 语句不适用于 HTTP_HOST

macos - Mac apache localhost 给出 403 Forbidden

非标准端口上的 Apache vhost 配置 - 仅提供第一个 vhost

java - 生命周期异常 : Failed to start component

.htaccess - 使用 htaccess 将 url 从 Joomla 文章重定向到 K2 文章

php - Codeigniter 3 删除 index.php 问题

Apache :MyFaces 和战斧

wordpress - 利用浏览器缓存不起作用

php - 为什么 .htaccess 和 .htpasswd 不接受我的登录信息