2017-08-27 53 views
1

我有這樣的結構的URL刪除重複的標記在URL:使用的.htaccess

http://website.coy/user/profile.php?id=123 

我創建了.htaccess

RewriteEngine on 
RewriteRule ^profile/(.*) user/profile/?id=$1 

結果變成一個不同的URL(?):

http://website.coy/profile/123 

上面的代碼工作得很好。但是有一點問題。

我重定向從http://的頁面https://

RewriteCond %{HTTPS} !=on 
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R] 

但是,發生了什麼?

瀏覽器顯示一個雜亂的URL結構,像這樣:

https://website.coy/profile/123?id=123 

如何修復這個錯誤,以顯示結構爲:

https://website.coy/profile/123 

回答

3

重寫之前,您必須重定向到https 。更改重寫規則的順序:

RewriteEngine on 

RewriteCond %{HTTPS} !=on 
RewriteRule^https://%{HTTP_HOST}%{REQUEST_URI} [L,R] 

RewriteRule ^profile/(.*) user/profile/?id=$1 
+1

是的我只是意識到我推翻了代碼。謝謝 –