0

I'm trying to setup virtual directories with .htaccess.

I want to use this directories as language indicators. E.g. example.com/de-de, example-com/de-en and so on. But in fact, the directories doesn't exist on the server and the index.html file at the root of the directory should be loaded. I wrote some rules, but they dont work properly:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]

URLs like example.com/de-de works, but example.com/de-de/ doesn't. When I open example.com/de-de/ it tries to load resources from the /de-de/ subdirectory, e.g. de-de/js/jquery.js instead of /js/jquery.js. Whats wrong with my rules? And is there a way to force a trailing slash, so users will be redirected from example.com/de-de to example.com/de-de/?

Sumurai8
  • 20,333
  • 11
  • 66
  • 100
Slevin
  • 4,268
  • 12
  • 40
  • 90
  • Define "does not work". Do you get an error (500 internal server error, 403 forbidden error or 404 not found error)? Does it instead load `/pretty-unicorns.php`? Does it load the correct page, but with the wrong parameters? – Sumurai8 Aug 14 '14 at 16:56
  • When open `example.com/de-de/` the site tries to load ressources from the `de-de` directory, e.g. `de-de/js/jquery.js` instead of `/js/jquery.js`. But `example.com/de-de` works. – Slevin Aug 15 '14 at 07:46
  • Then there is nothing wrong with your rules. You just have relative URL's in your website. See [this question](http://stackoverflow.com/questions/19292150/why-do-my-hyperlinks-go-to-the-wrong-directory/19292700#19292700). If that question answers your question, please mark this question as a duplicate of that question by using the 'flag' link under your question. – Sumurai8 Aug 15 '14 at 08:09
  • Yes, you are right! One question left: how can I force a trailing slash at the end? I tried adding `RewriteRule ^(.*)([^/])$ http://%{HTTP_HOST}/$1$2/ [R=301]` before `RewriteRule . /index.html [L]` but then I get a 500 error. – Slevin Aug 15 '14 at 08:17
  • At first glance that doesn't look like an unreasonable way to force a slash behind an url. In fact, it seems to be completely the same as [this one](http://stackoverflow.com/questions/7780859/htaccess-rewrite-to-force-trailing-slash-at-the-end). Again: If you have a problem with code, (1) post the code, (2) post exactly what error you get and (3) post what you expect to happen. An internal server error leaves some message in your Apache error log. Google that message. – Sumurai8 Aug 15 '14 at 08:22

0 Answers0