Isra
Isra

Reputation: 302

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

Upvotes: 0

Views: 453

Answers (1)

Abhishek Gurjar
Abhishek Gurjar

Reputation: 7476

Try with below rule,

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

Upvotes: 1

Related Questions