2017-09-03 39 views
0

您好,我有一個與301重定向.htaccess問題。301在一些URL上工作,而不是在其他人在htaccess

一切看起來很好,在90%的網址上,但不適用於任何個人博客文章重定向。

這裏是他們不重定向代碼:

RewriteRule ^blog-article.php?id=38 blog-post/xxxx-xxxxxx-xx-x-xxxxxxx/9/ [L,NC,R=301] 
RewriteRule ^blog-article.php?id=34 blog-post/xxxxxxx/4/ [L,NC,R=301] 

但所有其他301次重寫的工作,他們是這樣的:

RewriteRule ^old-url-portfolio/(.*)$ page/new-url-portfolio/$1 [L,NC,R=301] 
RewriteRule ^Portfolio/Detail/(.*)$ portfolio/$1 [L,NC,R=301] 

RewriteRule ^old-url/7/ page/new-url/ [L,NC,R=301] 
RewriteRule ^contact-us-old/ page/contact-us-new/ [L,NC,R=301] 
RewriteRule ^blog.php page/blog/ [L,NC,R=301] 

我找不到他們爲什麼不工作,它不是因爲那些不工作的是個人文件,因爲blog.php文件正在發送到新頁面。

任何想法,將不勝感激:)

回答

0

發現周圍的工作,它接縫的問題是id =號,所以我只是這樣做:

RewriteCond %{QUERY_STRING} ^id=38$ 
RewriteRule ^blog-article\.php$ http://www.xxxxxxx.co.uk/blog-post/xxxx-xxxxxx-xxxx/9/ [R=301,L] 
1

你不能對匹配的查詢字符串重寫規則的模式。要將blog-article.php?id = 123重定向到不同位置,您需要使用RewriteCond指令與%{QUERY_STRING}進行匹配。

RewriteCond %{QUERY_STRING} ^id=123$ 
RewriteRule ^blog-article.php$ /location/? [L,R] 

注:traling 在目標路徑的末尾非常重要,因爲它會丟棄舊的查詢字符串。

相關問題