2017-06-16 43 views
0

我一直在使用.htaccess ...第一個和最後一個分段這些URL需要被「重寫」需要拆除,所以的.htaccess重寫去除2個網址段

/articles/marketing-stuff/seo-management/1418/應該

成爲/marketing-stuff/seo-management/


/articles/command-line/linux-post/2131/需要

成爲/command-line/linux-post/


我有這些重寫規則,但他們不工作:

RewriteCond %{REQUEST_URI} /articles/marketing-stuff/(.*)/(\d+)/? 
RewriteRule ^/articles/marketing-stuff/(.*)/(\d+)/?$ /marketing-stuff/$1/ 

RewriteCond %{REQUEST_URI} /articles/command-line/(.*)/(\d+)/? 
RewriteRule ^/articles/command-line/(.*)/(\d+)/?$ /command-line/$1/ 

我缺少什麼?

回答

1

您可以使用:

RewriteEngine on 
RewriteRule ^articles/(marketing-stuff|command-line)/(.*)/(\d+)/?$ /$1/$2/ [NC,L] 
+0

這不是工作,最初的URL沒有改變,顯示出舊的頁面。我測試了我的.htaccess文件是否正在使用,它是 – Angelo

+1

如果您嘗試更改url,它不是重寫,而是重定向。使用'[NC,R = 301]'代替'[NC,L]' – Croises