Removing a trailing character at the end of a URL using htaccess

生来就可爱ヽ(ⅴ<●) 提交于 2020-02-06 09:52:47

问题


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]


来源:https://stackoverflow.com/questions/27435578/removing-a-trailing-character-at-the-end-of-a-url-using-htaccess

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!