简体   繁体   中英

How to rewrite the url if it does not have a prefix with .htaccess

The page should always have the prefix 'es', 'en', or 'fr' after the main domain, if someone type a url without the prefix then it should be set 'es' by default. Example:

www.mypage.com/games/sports -> www.mypage.com/es/games/sports

if it has any of the prefixes then it does not change.

www.mypage.com/en/games/sports -> www.mypage.com/en/games/sports

Try with below rule,

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/(es|en|fr)
RewriteRule ^ http://%{HTTP_HOST}/en%{REQUEST_URI} [R=301]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM