RewriteRule for a file in a parent directory

.htaccess, apache, mod-rewrite

Solution

- Check `DOCUMENT_ROOT` of your `m.domain.com`.

If `DOCUMENT_ROOT` for your `m.domain.com` is `/public_html/mob` then you cannot load `/public_html/index.php` without doing a full redirect (or proxy) to `http://domain.com/index.php`

- Just to clarify any web site cannot access files above its `DOCUMENT_ROOT` folder level.

Problem

I've got a site set up on an apache server with the desktop site in /public_html and a mobile site /in public_html/mob I'm trying to set up an .htaccess rewriterule to send users to an index.php file in /public_html if they visit the /mob folder. My current rewrite rule, in the mob subfolder is: ``` RewriteRule ^(/)?$ ../index.php ``` I can load up the same file in the mob subdirectory with: ``` RewriteRule ^(/)?$ index.php ``` However I can't seem to get the site to load the index.php file from the parent directory (public_html). When attempting to load http://www.domain.com/mob in a browser I receive: ``` Bad Request Your browser sent a request that this server could not understand. ``` This same rewriterule worked fine on our development server, but doesn't work in our live environment. The .htaccess file from the /public_html/mob folder is as follows: ``` Options +FollowSymLinks RewriteEngine on RewriteRule ^(/)?$ ../index.php [L,QSA] ``` When index.php is reached a mobile device detect script decides whether to load the content from the desktop or mobile site.

Original source