wordpress - WP htaccess 重定向正确但不起作用?
问题描述
我目前正在使用 Adforest 主题来制作分类广告网站,并且用户帐户默认为 /author/username。我使用了一个将 /author/ 更改为 /user/ 的插件,并且一切都按预期工作,但是要查看用户页面上的广告,您必须链接到 /user/username/?type=ads。我的目标是让 /user/username/ads(或只是 /user/username/)静默重定向到 /user/username/?type=ads,提供一个漂亮的永久链接结构。
当我尝试制定 htaccess 规则来完成此操作时,问题就出现了。我已经尝试了至少两打变体,但没有一个被证明是成功的。我已经通过第三方工具 ( https://htaccess.madewithlove.be ) 检查了我的 URL 是否符合 htaccess 规则,并确保每个都按预期工作,最新的“工作”规则在下面。但是,我仍然遇到了简单的问题,完全无法正常工作。我尝试过使用和不使用我第一次提到的插件被激活,以及刷新我的永久链接,每次我被带回同一个 404 页面。
任何对我没有理解的事情的见解将不胜感激!
上次使用的 htaccess 代码:
<IfModule mod_rewrite.c>
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^user/(.*)/ads$ /user/$1?type=ads [NE,NC,L]
</IfModule>
以及许多其他变体:
RewriteRule ^user/(.*)$ /user/$1?type=ads [L]
RewriteRule ^user/(.*)/$ /user/$1?type=ads [L]
RewriteRule ^user/([^/]*)/ads$ /user/$1?type=ads [L]
RewriteRule ^user/([^/]*)$ /user/$1?type=ads [L]
RewriteRule ^user/([^/]*)/$ /user/$1?type=ads [L]
...
为了完整起见,我当前的 htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
<IfModule mod_rewrite.c>
RewriteRule ^user/([^/]*)/ads$ /user/$1?type=ads [L]
</IfModule>
解决方案
推荐阅读
- r - 寻找一个 R 函数,它允许我根据 5 列中的匹配值汇总 df 中的数据
- exception-handling - springboot控制器测试不处理异常
- assembly - assembly 8086 multiply 41 without using MUL
- oauth-2.0 - 在什么情况下我需要实现 OAuth 2.0 JWT Bearer Token Flow?
- c - 用 Visual Studios 2017 编写的程序会在 linux 或 unix 环境中运行吗?
- django - 如何在嵌套序列化程序 DRF 中使用 POST 推送平面数据
- c# - Visual Basic 中的数组创建处理行驶距离的程序
- python - 是否可以在多输入神经网络中使用来自 sklearn 的 StratifiedKFold?
- amazon-web-services - aws codepipeline 批准/审查阶段不是构建最新的提交,而是构建每一个提交
- node.js - MEAN-Stack 中的 passport-jwt 返回内部服务器错误 500