Replace special character in htaccess

天大地大妈咪最大 提交于 2019-11-30 04:46:43

问题


I changed my forum from kunena to phpbb3. Problem is that my old forum (that is indexed in google) has special characters in urls. I want to keep my urls, so old link works with new forum - but only when special characters are replace with normal letters.

I need to use htaccess to convert characters on the fly.

for example

ą => a
ę => e
ś => s
ć => c

so in words letters will be replaced like this

pościelówka => poscielowka

Can someone help me with that? p.s. sorry for bad English ;)


回答1:


Try adding this to the htaccess file in your document root:

RewriteEngine On

RewriteRule ^(.*)ą(.*)$ /$1a$2 [L,R=301]
RewriteRule ^(.*)ę(.*)$ /$1e$2 [L,R=301]
RewriteRule ^(.*)ś(.*)$ /$1s$2 [L,R=301]
RewriteRule ^(.*)ć(.*)$ /$1c$2 [L,R=301]
RewriteRule ^(.*)ó(.*)$ /$1o$2 [L,R=301]

etc.

This redirects a URL like:

http://yourdomain.com/pościelówka

and redirects the browser to:

http://yourdomain.com/poscielowka

as long as the /poscielowka URI actually exists.



来源:https://stackoverflow.com/questions/18673576/replace-special-character-in-htaccess

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