重定向 /?p=xxx WordPress URL
我需要将一个格式如下的 WordPress URL 重定向到另一个域上的干净 URL:www.bluewidgets.com/?p=123
。如何通过 .htaccess
执行此操作?我见过的所有教程都说我需要在查询字符串之前指定网址的另一部分,例如 index.php
,但我的网址没有 - 它只是域名然后是查询字符串。
I need to redirect a single Wordpress URL that is formatted like this: www.bluewidgets.com/?p=123
to a clean URL on another domain. How can I do this via .htaccess
? All of the tutorials I've seen say that I need to specify another part of the url, like index.php
, before the query string, but my URL doesn't have one - it's just the domain and then the query string.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
难道你不能在其他任何事情之前添加到 header.php 中吗:
我过去做过类似的事情。它可能不漂亮,但它有效 - 我很想听听更有经验的 PHP 人员的意见,这是否是一个合法的策略。
Can't you just add to the header.php, before anything else:
I've done something similar in the past. It may not be pretty, but it works - I'd be interested to hear from more experienced PHP-ers whether it's a legitimate tactic.
试试这个规则:
或者使用REQUEST_URI:
请注意,
RewriteCond
模式以=
开头,它标识字典比较而不是正则表达式测试。此外,替换中的空查询(用…?
表示)将删除最初请求的查询。Try this rule:
Or using REQUEST_URI:
Note that the
RewriteCond
patterns begin with a=
that identifies a lexicographical comparison instead of a regular expressions test. Additionally the empty query in substitution (denoted with…?
) that will remove the originally requested query.WordPress 不是已经内置了 URL 漂亮化功能吗?只是出于好奇为什么你需要这样做。
除此之外,是的,你提到的是如何通过 htaccess 做到这一点。您在使用此方法时遇到问题吗?
Doesn't wordpress already have built in URL prettyfication? Just out of curiosity why would you need to do this.
Aside from that, yes what you mention is how you'd do it via htaccess. Are you encountering an issue with this method?
标准 301 重定向的格式为(并且位于domain1):
但我只是尝试使用默认永久链接,但它不起作用。
在domain1上,您可以使用标准wordpress重写块重写URL,然后立即将其重定向到domain2。凌乱,但可能有用。
A standard 301 redirect is in the format (and would be at domain1):
but I just tried that with default permalinks and it didn't work.
On domain1, you could rewrite the URL with the standard wordpress rewrite block, and then immediatly redirect it tp domain2. Messy, but it might work.