2017-02-14 51 views
1

我已經建立了一個網站的食譜,但在遷移的過程中,舊的URL轉到新的URL我面臨的問題。重定向的提取URL

https://example.com/recipes/cheesy-baked-tacos/

這是我的舊的URL結構,在WordPress網站我需要提取URL「俗氣出爐,玉米餅」的最後一部分和處理,在我使用的配方頁面的模板。

現在,當我點擊URL時,即使食譜頁面已經設置,它也會進入404頁面。

我嘗試以下htaccess的規則,但沒有成功提前

RewriteBase/
RewriteRule ^recipes/(.*)$ index.php?l=$1 

感謝。

完全htaccess文件看起來像這樣

# BEGIN WordPress 
<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/
RewriteRule ^recipes/(.*)$ index.php?l=$1 
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
</IfModule> 
# END WordPress 
+0

您是否啓用了RewriteEngine?要啓用它,您需要在htaccess頂部的**上使用** RewriteEngine。 – starkeen

+0

你的規則對我來說看起來不錯。你要去哪個網址? – starkeen

+0

,將我引導到404頁面 –

回答

0

託管與301重定向解決問題。這是我使用的,如果它幫助某人。

# BEGIN WordPress 
<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/
RewriteRule ^recipes/(.*)$ recipe/?post_name=$1 [L,R=301,NC] 
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
</IfModule> 
# END WordPress 
0
you should check your permalink change to starts with id to without query string 
dont change htacces file 
you just change permalink in new server 
https://example.com/recipes/cheesy-baked-tacos/ 
this is your old url and has permalink set without query string 

new url https://example.com/recipes/cheesy-baked-tacos/id=50 just like 
thats why your code have error 
+0

不,我們已經在我們的社交媒體網絡中擁有數千個這樣的OLD網址。我們無法逐一更新它們以包含該ID。我只需要一種方法來自動化這個過程。 –