.htaccess - 如何在这些情况下正确重写 htacess?
问题描述
我在 htaccess 中很新,我在这些情况下遇到了一些麻烦
- 我只需要对这个特定的 URL 进行 301 重定向:
example.com/jobs 到 example.com/browse-jobs
如果 url 是 example.com/jobs/job1 它不会重定向。
将所有具有路径 /product 的 URL 重定向到 /package。例如:example.com/product 和 example.com/product/1,所有这些 URL 都会重定向到 example.com/package。
重写网址:
example.com/browse-jobs/?job_type=internship 重写为 example.com/browse-jobs/intership。
如果 URL example.com/browse-jobs/?posted=14days&job_type=internship 不要重写并保持不变。
我整天都在与这些案例作斗争,我检查了所有参考网站,但仍然不知道如何使它正确。如果有人知道这件事,请帮助我。谢谢你。
解决方案
如果您一直在尝试,我建议您清除缓存,也许重新启动 apache:
RewriteBase /
# product, products, product/abc, product/a/b/c to package
# If you don't want products to redirect, add $ after the ?
RewriteRule ^product(/.*)? package [R=301]
# Exactly jobs with or without / to browse-jobs
RewriteRule ^jobs/?$ browse-jobs [R=301]
# If query string only contains parameter job_type with value internship
RewriteCond %{QUERY_STRING} ^job_type=(internship)$
# With or without slash
RewriteRule ^(browse-jobs)/?$ $1/%1 [QSD,R=301]
# QSD = Discard the query string
推荐阅读
- javascript - 每当我在 Postman 上运行请求时更新日期和点数
- javascript - 如何使用 ARN 从 Secrets Manager 获取密钥
- c++ - 如何将 HSV 掩码转换为 BGR?
- html - 居中带边距的元素不起作用
- javascript - keydown Escape 事件后更改/加载事件中断
- javascript - text/html 复制到剪贴板,没有任何样式
- php - 如何在 Symfony 中使用 Guzzle 客户端发送参数?
- flutter - 如何在 Flutter 的页面认证中保存用户登录?
- php - 当给定作曲家安装时,我在 laravel 托管的代码中得到了这个错误,而不是在本地主机中
- binding - QML Loader:设置“source:”属性一次且仅一次