I have a site with about 500 pages, all in Hebrew. I want to change all the all paths to include the language prefix. This would be the first stage in turning this site into a sub-site (with a sub-domain).

Is this possible without third-party modules?

  • Pathauto is just for nice URLs. You're talking about changing routes themselves.
    – Kevin
    Dec 17, 2016 at 16:53
  • You can do this by writing rewrite rule in the .htaccess file located in the Drupal Root directory. Check this answer.
    – Yogesh
    Dec 20, 2016 at 6:34
  • Maybe, this answer will help you ? Here is described the solution for Drupal 8, how to change urls on your site. drupal.stackexchange.com/questions/190232/… Dec 20, 2016 at 7:56
  • Since your requirement is for a sub-site (with a sub-domain), it's better to configure the site with a sub-domain that uses he as prefix. In order to create a multi-site, follow the steps given in the first answer for drupal.stackexchange.com/questions/223525/….
    – developer
    Dec 22, 2016 at 5:58

3 Answers 3


These are the rewrite rules to add in the .htaccess file located in the Drupal root directory.

RewriteEngine on
RewriteCond %{REQUEST_URI} !/he
RewriteRule ^(.*) http://www.domain.com/he%{REQUEST_URI} [L,R=301]

Since you are making this specific to a language prefix, I would suggest using the Language module, since it is part of Drupal core and it's easy to manage.

Enable the Language module, which isn't enabled by default, unless you made your site explicitly multilingual, your content is in Hebrew, but your site default language is English.
You need two languages for the language prefixing to work. On /admin/config/regional/language, add a second language. This will enforce the use of language prefixes.
On /admin/config/regional/language/detection, configure the URL detection method; this should be in fact activated and preceding all other options. Set the path prefix for the default language to he.
Save and clear the cache. All your Drupal paths now will be prefixed by he.

The existing URLs are still valid. A couple of clicks into navigation and your URLs should be prefixed with he.


If you wish to have different subdomains for different languages, I think Drupal should be able to detect the language code from the sub-domain and there should be no necessity for adding URL prefixes. You can take the first step by setting up the sub-domain he.example.com and redirecting requests from your main site to the he subdomain until you add other languages and a language selection dialog in example.com (without sub-domains).

Hello! I can see the following solutions:

Solution 1: Altering node paths

  • Using pathauto (which you do not wish to use) you can set the node prefix to /he/.
  • Running a one-time script to add a prefix to all node URL aliases and in the future adding the /he prefix manually.

Solution 2: .htaccess

Using .htaccess to re-write all URLs to interpret /he/* URLs as /*. But this might also apply the prefix to other paths - doing this only for nodes might be difficult depending on their existing URLs.

RewriteEngine on
RewriteCond %{REQUEST_URI} !/he
RewriteRule ^(.*) http://www.domain.com/he%{REQUEST_URI} [L,R=301]

NOTE: Code extract copied from Ashish Deynap's answer.

But I've heard that it is better to avoid .htaccess redirects as far as possible because:

  • The .htaccess might be updated with Drupal versions.
  • The rules in .htaccess are evaluated for every request! The more rules you have, the more time the server spends evaluating them.

Hope it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.