首页 > 解决方案 > 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>

标签: wordpress.htaccess

解决方案


推荐阅读