Removing a trailing character at the end of a URL

2019-09-04 06:16发布

问题:

I have a url: www.example.com/tattoo-ink-radiant-colors-teal/

I need it to change to

www.example.com/ink-wineberry/

so far I have

the following in my htaccess as a temporary fix

RewriteEngine On
RewriteBase /
RewriteCond   %{REQUEST_FILENAME} !-f
RewriteCond   %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ink
RewriteRule -1oz/ /ink [R=301,L]

edit* to make it simpler here are a few more examples

tattoo-ink-radiant-colors-teal-1oz/ should be tattoo-ink-radiant-colors-teal/

tattoo-ink-radiant-super-white-1oz/ should be tattoo-ink-radiant-super-white/

回答1:

It's ok with:

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)-1oz/?$ $1/ [R=301,L]