Angelo
Angelo

Reputation: 427

.htaccess rewrite for removing 2 url segments

I have these URLs that need to be 'rewritten' using .htaccess... The first and last segment need to be removed, so

/articles/marketing-stuff/seo-management/1418/ should

become /marketing-stuff/seo-management/


/articles/command-line/linux-post/2131/ needs to

become /command-line/linux-post/


I have these rewrite rules but they're not working:

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/

What am I missing?

Upvotes: 0

Views: 118

Answers (1)

Croises
Croises

Reputation: 18671

You can use:

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

Upvotes: 1

Related Questions