【问题标题】:Writing redirecting URL in htaccess in wordpress在 wordpress 中的 htaccess 中编写重定向 URL
【发布时间】:2015-10-28 10:21:04
【问题描述】:

我现在的网址是

http://localhost/removalcenter/landing-page/?from=Algeria&to=Afghanistan&submit=Submit

我想在用户输入 URL 时重定向到当前 URL
http://localhost/removalcenter/removals-from-Algeria-to-Afghanistan
from 和 to 是查询字符串变量
我的 htaccess 代码是..

 # BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /removalscenter/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /removalscenter/index.php [L]
</IfModule>
# END WordPress


请向我提供此重定向的规则。

【问题讨论】:

标签: wordpress apache .htaccess redirect


【解决方案1】:

你必须把这段代码放到你的functions.php中

我没有测试它!这只是一个示例,因为您询问了一些代码。

之后,您必须转到 wordpress 设置 -> 永久链接,然后只保存设置。如果您不这样做,您将收到 404 错误。

阅读wordpress codex的信息:

重要提示:不要忘记刷新并重新生成重写规则 修改规则后的数据库。从 WordPress 管理屏幕, 选择 Settings -> Permalinks 然后点击 Save Changes without any 变化。

function custom_rewrite_basic() {
  add_rewrite_rule('^removalcenter/landing-page/removals-from-Algeria-to-Afghanistan/?', '/removalcenter/landing-page/?from=Algeria&to=Afghanistan&submit=Submit', 'top');
}
add_action('init', 'custom_rewrite_basic');

【讨论】:

  • from 和 to 是查询字符串变量。如何处理这些??
  • 他的意思是阿尔及利亚和阿富汗是可以随着每个请求而改变的变量。
  • 他必须看看从 wordpress 重写标签。 codex.wordpress.org/Rewrite_API/add_rewrite_tag
猜你喜欢
  • 2013-08-01
  • 1970-01-01
  • 2016-07-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多