2017-10-12 127 views
2

參數,以新的SEO URL要重定向PARAM網址,以搜索引擎友好的URL如何的舊網址重定向使用htaccess的

https://example.com/a.php?slug=vr-promised-us-the-future-too-bad-we-re-stuck-in-the-present

https://example.com/vr-promised-us-the-future-too-bad-we-re-stuck-in-the-present

https://example.com/tag.php?id=Virtual-reality

https://example.com/tag/Virtual-reality

我當前的.htaccess代碼

RewriteEngine On 

RewriteRule ^([a-zA-Z0-9_-]+)/?$ a.php?slug=$1 [L] 


RewriteCond %{HTTP_HOST} ^www\. [OR] 
RewriteCond %{HTTPS} off 
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ 
RewriteRule^https://%1%{REQUEST_URI} [NE,L,R] 
+0

這htaccess的仍然是動態的(多域)和無域寫在所以不要更改它,並使用託管管理中的CNAME添加站點域,並添加虛擬主機以指向新的本地文件夾。 – 2017-10-12 16:43:59

+0

@headmax感謝回覆,其實我的問題是如何阻止重複的網址(重定向舊=> /a.php?slug=vr-promised-us-the-future-too-bad-we-re-stuck-in-現在到/ vr-promised-us-the-future-too-bad-we-re-stuck-in-the-present) – pra021

回答

2

有這樣說:

Options -MultiViews 
RewriteEngine On  

RewriteCond %{HTTP_HOST} ^www\. [OR] 
RewriteCond %{HTTPS} off 
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ 
RewriteRule^https://%1%{REQUEST_URI} [NE,L,R=301] 

# external redirect to redirect old URL to pretty URL  
RewriteCond %{THE_REQUEST} /a\.php\?slug=([^\s&]+) [NC] 
RewriteRule^/%1? [R=301,L,NE] 

RewriteCond %{THE_REQUEST} /tag\.php\?id=([^\s&]+) [NC] 
RewriteRule^/tag/%1? [R=301,L,NE] 

RewriteRule ^tag/([\w-]+)/?$ tag.php?id=$1 [L,QSA,NC] 

# internal rewrite to forward to actual URL 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^([\w-]+)/?$ a.php?slug=$1 [L,QSA] 
+1

謝謝兄弟:) – pra021

+0

編輯了答案。 – anubhava

相關問題