将 url 更改为 htaccess wordpress 中的查询变量
Change the url as the query var in htaccess wordpress
我有一个 url 喜欢 http://exmple.com/company/?n=Brunswick%20&%20Sons。
首先,我已经阅读了这篇post。 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% 完成这项工作。
在 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= [B,NC,L]
我有一个 url 喜欢 http://exmple.com/company/?n=Brunswick%20&%20Sons。
首先,我已经阅读了这篇post。 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% 完成这项工作。
在 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= [B,NC,L]