Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RewriteRule for a file in a parent directory

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.

like image 375
James Avatar asked Nov 28 '13 14:11

James


2 Answers

  • 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.
like image 63
anubhava Avatar answered Nov 10 '22 19:11

anubhava


If your rule's target starts with a /, that makes it an absolute URI starting from the document root, which I assume would be the public_html folder:

RewriteRule ^(/)?$ /index.php
like image 1
Jon Lin Avatar answered Nov 10 '22 19:11

Jon Lin