2

is the following scenario possible and how do I archive that in a shared hosting environment?

I have a Wordpress installation which resides in, say,

/httpdocs/wordpress

My domain points to this folder. So calling

http://example.com 

results in the Wordpress page. Now I want to add a second system. But I don't want to pollute my Wordpress and want to store it outside of this folder. I still want it to be accessible via

http://example.com/other-system

even though it resides in the filesystem in

/httpdocs/other-system

and not

/httpdocs/wordpress/other-system

Is that possible? Am I making any sense? Thanks!

3
  • which web server are you using? Apache? please post your current virtual host configuration of your respective web server for this example – Hrvoje Špoljar Nov 8 '14 at 19:32
  • The problem is, that this is hosted in a shared environment, so I can only work with .htaccess. I cannot change the vhost settings myself. It is Apache, if that is of any help. It's a clients site so I cannot do that much to change the environment... – Øle Bjarnstroem Nov 8 '14 at 19:53
  • Since this is a shared hosting environment, don't you have any control panel interface? Parallels Plesk perhaps? – Vicky Nov 10 '14 at 23:28
2

I think what you want is

Alias /other-system /httpdocs/other-system

See Alias. In .htaccess, instead you can use

RewriteEngine on
RewriteRule ^/other-system/(.*)  /httpdocs/other-system/$1 [QSA]
5
  • Alias wont work in .htaccess – Hrvoje Špoljar Nov 8 '14 at 19:58
  • Alias looks exactly like what I need. Sadly it is a shared hosting environment so I can only work with .htaccess. Thanks anyway! – Øle Bjarnstroem Nov 8 '14 at 20:12
  • Added equivalent RewriteRule. – Andrew Schulman Nov 8 '14 at 22:34
  • RewriteRule in .htaccess does not work as in server config. Your rewrite rule will not work: example.com/other-system/ => other-system/ => does not match (Note the abscence of begin "/"). If you remove begin "/", you have a match but example.com/other-system/ => example.com/httpdocs/other-system... – Zimmi Nov 9 '14 at 16:31
  • core:error The given path was above the root path – tim Jun 16 '20 at 0:33
0

As far as I know you cannot use RewriteRule in .htaccess files to go out of your DocumentRoot, because this DocumentRoot will always be added at the beginning of the rewritten url.

I would advise to put each app in a separate folder under your DocumentRoot. For example, use DocRoot/wordpress and DocRoot/other.

Now if you want nice urls like

www.example.com => wordpress app

www.example.com/other => the other-system app

and also want that url like www.example.com/wordpress are redirected to www.example.com, then you could use something like the following in your .htaccess file:

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} !=""
RewriteRule .  -  [L]

RewriteCond %{REQUEST_URI} ^/other/(.*)?$
RewriteRule . - [L]

RewriteBase /
RewriteCond %{REQUEST_URI} ^/wordpress/.*$
RewriteRule ^wordpress/(.*)$ $1 [R=301,L]

RewriteCond %{REQUEST_URI} !^/wordpress/.*$
RewriteRule ^(.*)$ /wordpress/$1 [L]

The second rewrite rule matches the other app, does nothing but sets it as the last rewrite in this pass.

The third rewrite makes a permanent redirect from example.com/wordpress to example.com.

Now the first rule does nothing too but if the redirect is set to something in the pass before, it stops. This avoids an infinite redirect loop.

The last rewrite redirects internally everything to wordpress folder. Url in browser stays without the wordpress folder in it.

I’d be curious to know if it works with your apps... Hope it brings you further.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.