I have a site with about 500 pages (nodes, taxonomy pages, and some views) which are all in Hebrew.

I want to make all paths from say:




I want it to be for all pages whatsoever, as a first stage in turning this site to be a subsite (with a subdomain).

Is this possible in Drupal 8 without contrib modules? i.e without installing Pathauto for example?

  • Pathauto is just for nice URLs. You're talking about changing routes themselves. – Kevin Dec 17 '16 at 16:53
  • AFAIK, Pathauto also have extra functionality that can effect this (bulk create or bulk rewrite patterns for paths). – user16289 Dec 17 '16 at 16:56
  • 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/… – Yakimkin Roman Dec 20 '16 at 7:56

Here is the Rewrite Rule to be written in .htaccess file located in Drupal Root directory.

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

Hope, it makes sense to you.

| improve this answer | |
  • This is problematic, given that .htaccess is re-created in each Drupal minor update... – user16289 Dec 20 '16 at 6:52
  • 1
    The simple solution is to write all of your .htaccess customizations into a .htaccess_custom file in the site's webroot. After the core update, cat the .htaccess_custom to .htaccess i.e. cat .htaccess_custom >> .htaccess – Ashish Deynap Dec 21 '16 at 4:16
  • For reference, see to this drupal.org/node/1018190. Also, there is a module module for this in d7 drupal.org/project/htaccess. – Ashish Deynap Dec 21 '16 at 4:17
  • I personally work with D8 but in any case, if you don't want to use a module you will have to either do it manually after each update or find someway to do it automatically efficiently. – user16289 Dec 21 '16 at 4:20
  • then it has to be done manually or can be done through diff/patch(not a recommended solution from my side). – Ashish Deynap Dec 21 '16 at 5:06

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.

| improve this answer | |

Since you are making this specific to a language prefix, I would suggest using the core module "Language", since it is (a) core and (b) easy to manage. Try the following:

  1. Enable the "Language" (language) module; it's not enabled by default
  2. Unless you made your site explicitely multilingual, your content is in Hebrew, but your site'ŝ default language is English. You can ignore this if this is not the case.
  3. You need two languages for the language prefixing of URLs to work. If you already have two languages, e.g. he and en, you can skip this. Go to admin/config/regional/language and add a second language to your Drupal instance (it doesn't matter which one) => this will enforce the use of language prefixes (see the next step).
  4. Go to admin/config/regional/language/detection and configure the "URL" detection method; this should be in fact activated and preceding all other options.
  5. Set the path prefix for the default language to 'he'.
  6. Save and clear cache. All you Drupal paths now will be prefixed by 'he'.

Good luck!

N.B.: The existing URLs are still valid, but, a couple of clicks into navigation your URLs should be prefixed with 'he'.

| improve this answer | |
  • Thank you dearly Stefanos. Assuming I do it this way, Drupal will already make 301's, right (I had some painful incidents when Drupal 6 and 7 didn't create automatic redirects and I had to install modules for that). Will Drupal 8 make redirects or sould I also install the famous Drupal 8 "Redirect" module? – user16289 Dec 26 '16 at 20:22
  • This will not create any redirects I am afraid, simply new URLs/routes for your content. It's a minimal solution that covers the overall '/he/' prefixing using core only. The rest would need to be .htaccess-ed or contrib-ed. One point about the .htaccess concerns about updates overwriting it. If you would soltlink your custom .htaccess, e.g. .htaccess_custom to .htaccess, the update would not overwrite your custom file. In case this helps... – Stefanos Petrakis Dec 26 '16 at 20:31
  • Yes, but I must have .htaccess updated... I might use apache2.conf instead, it seems like the most minimalist solution. – user16289 Dec 26 '16 at 20:37

You can do this by writing rewrite rule in .htaccess file located in Drupal Root directory. Check this ans.

| improve this answer | |
  • This is problematic, given that .htaccess is re-created in each Drupal minor update... – user16289 Dec 20 '16 at 6:34
  • You can skip .htaccess file during minor updates, or you can include these changes again if there are more changes in new .htaccess file in new version of Drupal Core. – Yogesh Dec 20 '16 at 6:36
  • 2
    Or if you don't want to modify .htacess you can do these changes in Apache vhost configuration as well. Check this ans. – Yogesh Dec 20 '16 at 6:37
  • Using apache2.conf instead of .htaccess might be possible as well. – user16289 Dec 26 '16 at 16:00

AS your requirement is for a subsite (with a subdomain). Its better to configure the website with a sub domain as 'he'. Inorder to create multisite ,follow the steps given in the first answer of the link Drupal 8: Multi-sites in subdirectories not working

Hope it helps you.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy