【问题标题】:Change the url as the query var in htaccess wordpress将 url 更改为 htaccess wordpress 中的查询变量
【发布时间】:2015-12-12 10:37:56
【问题描述】:

我有一个类似http://exmple.com/company/?n=Brunswick%20&%20Sons 的网址。

首先,我已经阅读了这篇文章。 https://serverfault.com/questions/214512/redirect-change-urls-or-redirect-http-to-https-in-apache-everything-you-ever

但我不能轻易理解重写规则。我希望查询类似于http://exmple.com/company/Brunswick%20&%20Sons。

任何人都可以帮助理解这件事 100% 完成这项工作。

【问题讨论】:

  • 你已经尝试了什么?

标签: wordpress apache .htaccess mod-rewrite rewrite


【解决方案1】:

在 root/.htaccess 中尝试以下代码:

  RewriteEngine On

#1)Redirect from http://example.com/company/?q=foo
#to http://example.com/foo
RewriteCond %{THE_REQUEST} /company/\?n=(.+)\s [NC]
RewriteRule ^ /%1? [B,NC,L,R]
#first round of rewriting ends here


 #2) in this round , mod_rewrite will
 #internally map http://example.com/foo to
#http://example.com/company/?n=foo.
#the following 2 conditions check if the /foo is an existent directory or file, skip the rewrite
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ /company/?n=$1 [B,NC,L]    

【讨论】:

  • 在第一个中,您说 RewriteCond %{THE_REQUEST} /company/\?n=(.+)\s [NC] 是从example.com/company/?q=foo 更改为example.com/foo 的条件。但我想要example.com/company/foo。所以我应该使用这个。 %{THE_REQUEST} /\?n=(.+)\s [NC] 以及对此的重写规则是什么。
  • 我找到了解决方案。谢谢。
猜你喜欢
  • 2013-08-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-12-24
  • 2013-04-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多