url - .htaccess 如何为 seo 友好的 url 编写 htaccess 重写规则

标签 url seo

我是 .htacces 的新手

我要:

example.com/page.php?page=how-to-learn

改为: example.com/how-to-learn

我用谷歌搜索了一些并尝试了但没有更改 url。

最佳答案

这不是 .htaccess 的工作方式:它不会更改您的链接以显示更正后的版本,但它会在您将写入其中的表达式中寻找匹配项以重写正确的参数。

例如,在您的代码中,您的 .htaccess 看起来像这样:

RewriteEngine On
RewriteRule ^([a-z-]+)$  page.php?page=$1 [QSA,L]

如果您在浏览器中输入 example.com/how-to-learn,您将能够看到 example.com/page.php?page=how-to-learn 的内容。

不过我建议您要非常小心:由于表达式非常宽松,您必须检查 page.php 文件是否合法允许加载该文件。

关于url - .htaccess 如何为 seo 友好的 url 编写 htaccess 重写规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42629614/

相关文章:

python - 网址设计 : ways to hide pk/id from url

jquery - 使用 javascript 而非常规 anchor 移动到我网站中的其他页面

c# - ASP.NET 产品网站的路由规则

javascript - 如何使用 angular.js 获取 URI 组件

ajax - AJAX 搜索引擎优化注意事项

magento - 如何解决 Magento 中的重复内容问题?

php - 如何避免重复内容?重定向 301/404?

apache - htaccess mod 重写具有多个参数的同一 URL

.htaccess - mod_rewrite : Redirect request to subdir with many subfolders of different structures + redirect to index. php

java - 使用 Java 从 URL 下载 EXE 文件出现兼容性错误