2015-12-11 76 views
1

我有一個像http://exmple.com/company/?n=Brunswick%20&%20Sons的網址。更改網址爲htaccess中的查詢var WordPress的

首先,我已閱讀此帖。 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%。

+0

你有什麼已經嘗試過? – hjpotter92

回答

1

嘗試在根/ .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]  
+0

首先,您表示RewriteCond%{THE_REQUEST} /company/\?n=(.+)\s [NC]是從http://example.com/company/?q=foo更改爲http: //example.com/foo。但是我想要http://example.com/company/foo。所以我應該使用這一個。 %{THE_REQUEST} /\?n=(.+)\s [NC]以及對此的重寫規則是什麼。 – Ranjit

+1

我得到了解決方案。謝謝。 – Ranjit