homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

htaccess syntax question
equivalent of "../" in htaccess?

10+ Year Member

Msg#: 4095540 posted 5:22 pm on Mar 11, 2010 (gmt 0)

if I use

RewriteRule ^(.*)$ dir/file1.php [L]

in the directory for sub.domain.com, then browsing to sub.domain.com/whatever.php will deliver sub.domain.com/dir/file1.php, while the browser address field still display sub.domain.com/whatever.php
So far so good...

But if I want to deliver a file that is located in "../domain/file2.php" (i.e. go up one step in the directory hierarchy and then...), how would I specify that? What I have in mind is to do something like this:

RewriteRule ^(.*)$ ../domain/file2.php [L]

The problem is that using 2 dots does not seem to work in htaccess... what is the equivalent in htaccess?



WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

Msg#: 4095540 posted 7:47 pm on Mar 11, 2010 (gmt 0)

For that to work, the .htaccess file would need to be located one folder up on the server and the rules adjusted to suit.

Additionally, rewriting all URL requests to one index.php file is a recipe for disaster, as your script will not be able to serve a request for /robots.txt, or for your CSS or JS files, or for requests for images, for example.


10+ Year Member

Msg#: 4095540 posted 8:12 pm on Mar 11, 2010 (gmt 0)

well, was just intended as an imaginary example. In the real world I have domain.com and sub.domain.com. I want any file requests on the subdomain to be internally redirected to the main domain.

Example, sub.domain.com/whatever.php will deliver domain.com/whatever.php, and at the same time the browser address field will stay at sub.domain.com/whatever.php

the directory structure is such that both the subdomain directory and the main domain directory is contained in the same container directory (default by cpanel, so nothing I really do anything about)


WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member

Msg#: 4095540 posted 8:24 pm on Mar 14, 2010 (gmt 0)

For security reasons, mod_rewrite cannot do things like
RewriteRule ^(.*)$ ../domain/file2.php [L]

Also, if these sub-domains were created as "add-on domains" using cPanel, you may find that you cannot under any circumstances access example.com/<anything> filepaths from example.com/subdomain-folder/<anything> filepaths.

The alternatives in that case are to get a dedicated IP address, allowing you to define your subdomains as pointing to anywhere in the filesystem you like, or to use an external redirect, which *would* change the browser address bar.


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved