skip to Main Content

I’m hosting different sites

http://example.nl/example.nl/_sites/byos/
http://example.nl/example.nl/_sites/eggbot/
http://example.nl/example.nl/_sites/hslab/
http://example.nl/example.nl/_sites/prolactin/

And yes there is a folder that has the same name as the domain, there is a reason for that.

And I want the links to become:

http://example.nl/byos/
http://example.nl/eggbot/
http://example.nl/hslab/
http://example.nl/prolactin/

This is one of the many attempts:

RewriteEngine On 
Options +FollowSymlinks 
RewriteCond %{REQUEST_URI} !(.*)example.nl/_sites
RewriteRule ^(.*)$ example.nl/_sites/$1 [L]

And this one:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^example.nl/_sites/(.*)$ /$1 [L,NC,R]

The last one brings me close, it changes the address in what I want it to be, but it also results in a 404 now.
I also tried it with renaming the example.nl folder so it is not the same as the domain name but the problem seems to be the same.

In case it is important for later, I also have folders with files here:

http://example.nl/example.nl/_misc/
http://example.nl/example.nl/_plugins/

But I don’t care if those get renamed, since they won’t appear in the url bar, unless the user goes directly to one of those files, but I don’t care about that.

So how can I omit the example.nl/_sites/ part and still have the website working?

I have seen the similar questions on SO, but for me it looks like Chinese in another dialect.

—- edit:
using the following of the answer from anubhava:

RewriteCond %{HTTP_HOST}::%{THE_REQUEST} ^(?:www.)?([^:]+)::GETs/+1/_sites/(S*)s [NC]
RewriteRule ^ /%2 [R=301,NE,L]

RewriteCond %{HTTP_HOST} ^(?:www.)?(.+)$ [NC]
RewriteRule ^[^/]+/?$ %1/_sites%{REQUEST_URI} [L]

I don’t get a 404 anymore.
But this files for example:

http://hslab.nl/hslab.nl/_misc/bna.js

It tries to load it as:

http://hslab.nl/_misc/bna.js

Which fails. In the code it was targeted as:

src="../../_misc/bna.js"

In case it helps here is a screenshot of the folder hslab.nl:

enter image description here

2

Answers


  1. With your shown samples, could you please try following. Fair warning I have written this in mobile so yet to test it should work IMHO will test it in sometime too. Also since you mentioned there could be multiple domains so I have specifically put a condition to check if it’s example.nl here in case you want to rewrite request for any domain then we could omit that condition too.

    RewriteEngine ON
    RewriteCond %{HTTP_HOST} ^example.nl$ [NC]
    RewriteRule ^([a-zA-Z]+)/?$ %{HTTP_HOST}/_sites/$1 [L]
    

    Note: in case you directories/folders are not necessarily starting with alphabets and could be anything then change regex in above from ^([a-zA-Z]+)/?$ TO ^([.*])/?$

    Login or Signup to reply.
  2. Without hardcoding host name, you may try these rules in your site root .htaccess:

    RewriteCond %{HTTP_HOST}::%{THE_REQUEST} ^(?:www.)?([^:]+)::GETs/+1/_sites/(S*)s [NC]
    RewriteRule ^ /%2 [R=301,NE,L]
    
    RewriteCond %{HTTP_HOST} ^(?:www.)?(.+)$ [NC]
    RewriteRule ^[^/]+/?$ %1/_sites%{REQUEST_URI} [L]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search